remove unnecessary forks; add checking if disk is sleeping; remove disk name from legend
paulfantom committed
Jun 7, 2016 at 21:50 UTC
9a8ab8a46b20199016ae586c0b29efda27fcd50e
1 file changed
+9
-8
charts.d/hddtemp.chart.sh
+9
-8
@@ -24,12 +24,13 @@ hddtemp_create() {
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 ' ' '_'`)
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"
32
+ #echo "DIMENSION ${hddtemp_disks[i]} ${disk_names[i]} absolute 1 1"
33
+ echo "DIMENSION ${hddtemp_disks[i]} '' absolute 1 1"
34
done
35
return 0
36
}
@@ -38,14 +39,14 @@ hddtemp_create() {
39
hddtemp_last=0
40
hddtemp_count=0
41
hddtemp_update() {
41
- #local all
42
-
43
- local all=( `nc $hddtemp_host $hddtemp_port | sed -e 's/||/\n/g;s/^|//' | cut -d '|' -f3` )
42
+# local all=( `nc $hddtemp_host $hddtemp_port | sed -e 's/||/\n/g;s/^|//' | cut -d '|' -f3` )
43
+ local all=( `nc $hddtemp_host $hddtemp_port | awk 'BEGIN { FS="|" };{i=4; while (i <= NF) {print $i+0;i+=5;};}'` )
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]}"
47
+ end=${#hddtemp_disks[@]}
48
+ for ((i=0; i<end; i++)); do
49
+ echo "SET ${hddtemp_disks[$i]} = ${all[$i]}"
50
done
51
echo "END"
52