]> arthur.barton.de Git - netdata.git/blob - charts.d/hddtemp.chart.sh
better log management for charts.d.plugin - fixes #1144
[netdata.git] / charts.d / hddtemp.chart.sh
1 # no need for shebang - this file is loaded from charts.d.plugin
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     require_cmd nc || return 1
17         run nc $hddtemp_host $hddtemp_port && return 0 || return 1
18 }
19
20 # _create is called once, to create the charts
21 hddtemp_create() {
22         if [ ${#hddtemp_disks[@]} -eq 0 ]; then
23                 local all
24                 all=$(nc $hddtemp_host $hddtemp_port )
25                 unset hddtemp_disks
26                 hddtemp_disks=( `grep -Po '/dev/[^|]+' <<< "$all" | cut -c 6-` )
27         fi
28 #       local disk_names
29 #       disk_names=(`sed -e 's/||/\n/g;s/^|//' <<< "$all" | cut -d '|' -f2 | tr ' ' '_'`)
30
31         echo "CHART hddtemp.temperature 'disks_temp' 'temperature' 'Celsius' 'Disks temperature' 'hddtemp.temp' line $((hddtemp_priority)) $hddtemp_update_every"
32         for i in `seq 0 $((${#hddtemp_disks[@]}-1))`; do
33 #               echo "DIMENSION ${hddtemp_disks[i]} ${disk_names[i]} absolute 1 1"
34                 echo "DIMENSION ${hddtemp_disks[$i]} '' absolute 1 1"
35         done
36         return 0
37 }
38
39 # _update is called continiously, to collect the values
40 hddtemp_last=0
41 hddtemp_count=0
42 hddtemp_update() {
43 #        local all=( `nc $hddtemp_host $hddtemp_port | sed -e 's/||/\n/g;s/^|//' | cut -d '|' -f3` )
44 #       local all=( `nc $hddtemp_host $hddtemp_port | awk 'BEGIN { FS="|" };{i=4; while (i <= NF) {print $i+0;i+=5;};}'` )
45         OLD_IFS=$IFS
46         set -f
47         IFS="|" all=( $(nc $hddtemp_host $hddtemp_port 2>/dev/null) )
48         set +f
49         IFS=$OLD_IFS
50
51         # check if there is some data
52         if [ -z "${all[3]}" ]; then 
53                 return 1
54         fi
55
56         # write the result of the work.
57         echo "BEGIN hddtemp.temperature $1"
58         end=${#hddtemp_disks[@]}
59         for ((i=0; i<end; i++)); do
60                 # temperature - this will turn SLP to zero
61                 t=$(( ${all[ $((i * 5 + 3)) ]} ))
62                 echo "SET ${hddtemp_disks[$i]} = $t"
63         done
64         echo "END"
65
66         return 0
67 }