forked from NEMSLinux/legacy-nems-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmonitorix.sh
More file actions
executable file
·75 lines (65 loc) · 2.53 KB
/
monitorix.sh
File metadata and controls
executable file
·75 lines (65 loc) · 2.53 KB
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
#!/bin/bash
# This script generates all the images for Monitorix via cronjob rather than on-demand, giving the perception of much faster processing and reducing load on page refresh
# It also ensures certain graphs (ie. Yearly) are not updated every time since the data won't be affected
# Ping Google to see if Internet is up. Don't begin until we have Internet.
count=1
while ! ping -c 1 -W 1 google.com; do
if [ $count -eq 60 ]
then
echo "Google not responding. Resuming, but if Internet is down, updates will fail."
break;
fi
((count++))
sleep 1
done
# Sometimes Monitorix (the daemon) stops responding even though it is running.
# Restart it here just in case, before loading the data.
/bin/systemctl restart monitorix
sleep 5
# Detect the default network interface and use it for net graphs
adapter=`/usr/local/share/nems/nems-scripts/info.sh nic`
/bin/cat <<EOF > /tmp/monitorix.nems
<net>
list = $adapter
<desc>
$adapter = Network on $adapter, 0, 10000000
</desc>
gateway = $adapter
</net>
EOF
if [ ! -f /etc/monitorix/conf.d/nems.conf ]; then
touch /etc/monitorix/conf.d/nems.conf
fi
/usr/bin/diff /tmp/monitorix.nems /etc/monitorix/conf.d/nems.conf
if [ $? == 1 ]; then
/bin/cat /tmp/monitorix.nems > /etc/monitorix/conf.d/nems.conf
/bin/systemctl restart monitorix
fi;
rm /tmp/monitorix.nems
# Only proceed if Monitorix is running
running=$(/usr/local/share/nems/nems-scripts/info.sh checkport 8080)
if [[ $running == 0 ]]; then
echo "Monitorix is not running. Aborting."
exit 1
fi
# Generate the graphs
if [[ $1 = "all" ]] || [[ $1 = "day" ]]; then
until $(/usr/bin/curl --output /dev/null --silent --fail "http://127.0.0.1:8080/monitorix-cgi/monitorix.cgi?mode=localhost&graph=all&when=1day&color=black"); do
sleep .5
done;
fi;
if [[ $1 = "all" ]] || [[ $1 = "week" ]]; then
until $(/usr/bin/curl --output /dev/null --silent --fail "http://127.0.0.1:8080/monitorix-cgi/monitorix.cgi?mode=localhost&graph=all&when=1week&color=black"); do
sleep .5
done;
fi;
if [[ $1 = "all" ]] || [[ $1 = "month" ]]; then
until $(/usr/bin/curl --output /dev/null --silent --fail "http://127.0.0.1:8080/monitorix-cgi/monitorix.cgi?mode=localhost&graph=all&when=1month&color=black"); do
sleep .5
done;
fi;
if [[ $1 = "all" ]] || [[ $1 = "year" ]]; then
until $(/usr/bin/curl --output /dev/null --silent --fail "http://127.0.0.1:8080/monitorix-cgi/monitorix.cgi?mode=localhost&graph=all&when=1year&color=black"); do
sleep .5
done;
fi;