-
Notifications
You must be signed in to change notification settings - Fork 0
/
node_exporter.sh
executable file
·88 lines (79 loc) · 2.9 KB
/
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env bash
echo "This shell script will perform following activities:"
echo " - Download node_exporter from 'https://prometheus.io/download/#node_exporter'"
echo " and save it as an executable at '/usr/local/bin/'"
echo " - Create a service file for service 'node_exporter' and start the service."
echo "Please enter 'y' to confirm the changes..."
read ans
prerequisites() {
if [[ $EUID -ne 0 ]]; then
echo "This script requires elevated permissions, therefore sudo access will be requested."
if hash sudo 2> /dev/null; then
SUDO=$(whereis sudo|cut -d" " -f2)
else
echo "Sudo not found. Please re-run the script as root."
exit 127;
fi
fi
if hash curl 2> /dev/null; then
DOWNLOADER='curl -L';
DOWNLOAD_OPTION='-o';
elif hash wget 2> /dev/null; then
DOWNLOADER='wget';
DOWNLOAD_OPTION='-O';
else
echo "Curl or Wget not found. Please install curl or wget and re-run the script."
exit 127;
fi
if ! hash tar 2> /dev/null; then
echo "Tar not found. Please install tar and re-run the script."
exit 127;
fi
}
get_node() {
cd /tmp/
$DOWNLOADER https://github.com/prometheus/node_exporter/releases/download/v0.15.1/node_exporter-0.15.1.linux-amd64.tar.gz $DOWNLOAD_OPTION /tmp/node_exporter.tar.gz
tar -xzf /tmp/node_exporter.tar.gz
$SUDO cp node_exporter-0.15.1.linux-amd64/node_exporter /usr/local/bin
rm /tmp/node_exporter.tar.gz
rm -rf /tmp/node_exporter-0.15.1.linux-amd64/
}
service_status () {
if [ "$?" -eq "0" ]; then
echo "Setup Complete. Your node metrics are now available on port 9100."
exit 0;
else
echo "Something bad happended. Exiting..."
$SUDO systemctl status node_exporter
exit 1;
fi
}
start_node() {
echo " Enter 'systemd' to create systemd service file or 'init' to create sysvinit script. "
read filetype
if [ "$filetype" == "init" ]; then
$SUDO $DOWNLOADER https://raw.githubusercontent.com/arush-sal/prom-stack/master/node_exporter.init.d \
$DOWNLOAD_OPTION /etc/init.d/node_exporter
$SUDO chmod +x /etc/init.d/node_exporter
$SUDO service node_exporter start
service_status
elif [ "$filetype" == "systemd" ]; then
$SUDO $DOWNLOADER https://raw.githubusercontent.com/arush-sal/prom-stack/master/node_exporter.service.systemd \
$DOWNLOAD_OPTION /etc/systemd/system/node_exporter.service
$SUDO systemctl daemon-reload
$SUDO systemctl enable node_exporter
$SUDO systemctl start node_exporter
service_status
else
echo "Sorry please try again."
exit 1;
fi
}
if [ "$ans" == "y" ] || [ "$ans" == "Y" ]; then
echo -e "\nThank you for your confirmation. Let's roll..."
prerequisites
get_node
start_node
else
exit 126;
fi