module alpine prometheus node_exporter

This commit is contained in:
Patrick CAO HUU THIEN 2022-11-28 15:25:14 +01:00
commit ac1e893583
3 changed files with 64 additions and 0 deletions

38
main.tf Normal file
View File

@ -0,0 +1,38 @@
resource "null_resource" "alpine_prometheus_node_exporter" {
triggers = {
source = filesha256("${path.module}/node_exporter.initd")
}
connection {
type = "ssh"
user = "root"
host = var.connection_ip
private_key = var.connection_private_key
}
provisioner "file" {
source = "${path.module}/node_exporter.initd"
destination = "/tmp/node_exporter.initd"
}
provisioner "remote-exec" {
inline = [
"echo '#--------------------------------'",
"echo '# module prometheus_node_exporter'",
"echo '#--------------------------------'",
"wget -nc -q https://github.com/prometheus/node_exporter/releases/download/v${var.node_exporter_version}/node_exporter-${var.node_exporter_version}.linux-amd64.tar.gz",
"tar xzf node_exporter-${var.node_exporter_version}.linux-amd64.tar.gz node_exporter-${var.node_exporter_version}.linux-amd64/node_exporter",
"echo '# install node_exporter in /usr/sbin'",
"install -Dm755 node_exporter-${var.node_exporter_version}.linux-amd64/node_exporter /usr/sbin",
#
"echo '# install service node_exporter'",
"install -Dm755 /tmp/node_exporter.initd /etc/init.d/node_exporter",
#
"echo '# enable service node_exporter'",
"rc-update add node_exporter",
"/etc/init.d/node_exporter start",
#
"echo '# module DONE'",
]
}
}

11
node_exporter.initd Normal file
View File

@ -0,0 +1,11 @@
#!/sbin/openrc-run
description="prometheus node exporter"
command="/usr/sbin/node_exporter"
command_args="--collector.disable-defaults --collector.cpu --collector.cpufreq --collector.diskstats --collector.filefd --collector.filesystem --collector.loadavg --collector.meminfo --collector.netclass --collector.netstat --collector.os --collector.time --collector.uname --collector.vmstat --web.disable-exporter-metrics "
pidfile="/run/${RC_SVCNAME}.pid"
# node_exporter stay in backgroud
command_background=true
# make a pid for me

15
variables.tf Normal file
View File

@ -0,0 +1,15 @@
variable "connection_ip" {
type = string
description = "ipv4"
}
variable "connection_private_key" {
type = string
description = "private key for terraform connection"
sensitive = true
}
variable "node_exporter_version" {
type = string
description = "like 1.5.2"
}