add script to monitor disk temperatures via hddtemp daemon
paulfantom committed
Jun 7, 2016 at 20:44 UTC
e71f2d62cd25d7ef81afb1b5ba89cf49f2f0f6f5
1 file changed
+53
charts.d/hddtemp.chart.sh
new
+53
@@ -0,0 +1,53 @@
1
+#!/bin/bash
2
+
3
+# if this chart is called X.chart.sh, then all functions and global variables
4
+# must start with X_
5
+hddtemp_host="localhost"
6
+hddtemp_port="7634"
7
+declare -A hddtemp_disks=()
8
+
9
+# _update_every is a special variable - it holds the number of seconds
10
+# between the calls of the _update() function
11
+hddtemp_update_every=3
12
+hddtemp_priority=90000
13
+
14
+# _check is called once, to find out if this chart should be enabled or not
15
+hddtemp_check() {
16
+ nc $hddtemp_host $hddtemp_port &>/dev/null && return 0 || return 1
17
+}
18
+
19
+# _create is called once, to create the charts
20
+hddtemp_create() {
21
+ if [ ${#hddtemp_disks[@]} -eq 0 ]; then
22
+ local all
23
+ all=$(nc $hddtemp_host $hddtemp_port )
24
+ unset hddtemp_disks
25
+ hddtemp_disks=( `grep -Po '/dev/[^|]+' <<< "$all" | cut -c 6-` )
26
+ fi
27
+ local disk_names
28
+ disk_names=(`sed -e 's/||/\n/g;s/^|//' <<< "$all" | cut -d '|' -f2 | tr ' ' '_'`)
29
+
30
+ echo "CHART hddtemp.temperature 'disks_temp' 'temperature' 'Celsius' 'Disks temperature' 'hddtemp.temp' line $((hddtemp_priority)) $hddtemp_update_every"
31
+ for i in `seq 0 $((${#hddtemp_disks[@]}-1))`; do
32
+ echo "DIMENSION ${hddtemp_disks[i]} ${disk_names[i]} absolute 1 1"
33
+ done
34
+ return 0
35
+}
36
+
37
+# _update is called continiously, to collect the values
38
+hddtemp_last=0
39
+hddtemp_count=0
40
+hddtemp_update() {
41
+ #local all
42
+
43
+ local all=( `nc $hddtemp_host $hddtemp_port | sed -e 's/||/\n/g;s/^|//' | cut -d '|' -f3` )
44
+
45
+ # write the result of the work.
46
+ echo "BEGIN hddtemp.temperature $1"
47
+ for i in `seq 0 $((${#hddtemp_disks[@]}-1))`; do
48
+ echo "SET ${hddtemp_disks[i]} = ${all[i]}"
49
+ done
50
+ echo "END"
51
+
52
+ return 0
53
+}