3 # if this chart is called X.chart.sh, then all functions and global variables
5 hddtemp_host="localhost"
7 declare -A hddtemp_disks=()
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
14 # _check is called once, to find out if this chart should be enabled or not
16 nc $hddtemp_host $hddtemp_port &>/dev/null && return 0 || return 1
19 # _create is called once, to create the charts
21 if [ ${#hddtemp_disks[@]} -eq 0 ]; then
23 all=$(nc $hddtemp_host $hddtemp_port )
25 hddtemp_disks=( `grep -Po '/dev/[^|]+' <<< "$all" | cut -c 6-` )
28 # disk_names=(`sed -e 's/||/\n/g;s/^|//' <<< "$all" | cut -d '|' -f2 | tr ' ' '_'`)
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 echo "DIMENSION ${hddtemp_disks[$i]} '' absolute 1 1"
38 # _update is called continiously, to collect the values
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;};}'` )
46 IFS="|" all=( $(nc $hddtemp_host $hddtemp_port 2>/dev/null) )
50 # check if there is some data
51 if [ -z "${all[3]}" ]; then
55 # write the result of the work.
56 echo "BEGIN hddtemp.temperature $1"
57 end=${#hddtemp_disks[@]}
58 for ((i=0; i<end; i++)); do
59 # temperature - this will turn SLP to zero
60 t=$(( ${all[ $((i * 5 + 3)) ]} ))
61 echo "SET ${hddtemp_disks[$i]} = $t"