-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.sh
executable file
·47 lines (39 loc) · 996 Bytes
/
plugin.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
#!/usr/bin/env bash
#
# Copyright 2020 Richard Case
#
# munin plugin to display VPS CPU throughput
file="/root/cpu-throughput/elapsed.log"
tmp="/root/cpu-throughput/tmp.log"
avg="0"
max="0"
mv "$file" "$tmp" >/dev/null 2>&1
if [ ! -f "$tmp" ]; then touch "$tmp"; fi
parse_elapsed() {
i="0"
while read -r num
do
avg=$(bc -l <<<"((($avg * $i) + $num) / ($i + 1))")
if [ "1" -eq $(bc -l <<<"$max < $num") ]; then max="$num"; fi
((i++))
done < "$tmp"
rm "$tmp"
}
if [ "$1" == "config" ]; then
echo "graph_title CPU throughput"
echo "graph_category vps"
echo "graph_vlabel seconds"
echo "graph_info This graph monitors the time taken to do a fixed amount of work"
echo "cpu_max.label maximum"
echo "cpu_max.type GAUGE"
echo "cpu_max.min 0"
echo "cpu_max.draw AREA"
echo "cpu_avg.label average"
echo "cpu_avg.type GAUGE"
echo "cpu_avg.min 0"
echo "cpu_avg.draw LINE2"
else
parse_elapsed
echo "cpu_max.value $max"
echo "cpu_avg.value $avg"
fi