forked from MadDamDam/opsschool-monitoring
-
Notifications
You must be signed in to change notification settings - Fork 20
/
inst_node_exporter.sh
51 lines (35 loc) · 1.56 KB
/
inst_node_exporter.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
# This script downloads and installs node_exporter of the requested version on a host.
# node_exporter is set up as a systemd service, which requiers a daemon-reload.
# BLAME: DamDam (Adam Bihari)
node_exporter_ver="0.18.0"
wget \
https://github.com/prometheus/node_exporter/releases/download/v$node_exporter_ver/node_exporter-$node_exporter_ver.linux-amd64.tar.gz \
-O /tmp/node_exporter-$node_exporter_ver.linux-amd64.tar.gz
tar zxvf /tmp/node_exporter-$node_exporter_ver.linux-amd64.tar.gz
sudo cp ./node_exporter-$node_exporter_ver.linux-amd64/node_exporter /usr/local/bin
sudo useradd --no-create-home --shell /bin/false node_exporter
sudo chown node_exporter:node_exporter /usr/local/bin/node_exporter
sudo mkdir -p /var/lib/node_exporter/textfile_collector
sudo chown node_exporter:node_exporter /var/lib/node_exporter
sudo chown node_exporter:node_exporter /var/lib/node_exporter/textfile_collector
sudo tee /etc/systemd/system/node_exporter.service &>/dev/null << EOF
[Unit]
Description=Node Exporter
Wants=network-online.target
After=network-online.target
[Service]
User=node_exporter
Group=node_exporter
Type=simple
ExecStart=/usr/local/bin/node_exporter --collector.textfile.directory /var/lib/node_exporter/textfile_collector \
--no-collector.infiniband
[Install]
WantedBy=multi-user.target
EOF
rm -rf /tmp/node_exporter-$node_exporter_ver.linux-amd64.tar.gz \
./node_exporter-$node_exporter_ver.linux-amd64
sudo systemctl daemon-reload
sudo systemctl start node_exporter
systemctl status --no-pager node_exporter
sudo systemctl enable node_exporter