]> arthur.barton.de Git - netdata.git/blob - charts.d/hddtemp.chart.sh
Merge pull request #2021 from ktsaou/master
[netdata.git] / charts.d / hddtemp.chart.sh
1 # no need for shebang - this file is loaded from charts.d.plugin
2
3 # netdata
4 # real-time performance and health monitoring, done right!
5 # (C) 2016 Costa Tsaousis <costa@tsaousis.gr>
6 # GPL v3+
7 #
8 # contributed by @paulfantom with PR #511
9
10 # if this chart is called X.chart.sh, then all functions and global variables
11 # must start with X_
12 hddtemp_host="localhost"
13 hddtemp_port="7634"
14 declare -A hddtemp_disks=()
15
16 # _update_every is a special variable - it holds the number of seconds
17 # between the calls of the _update() function
18 hddtemp_update_every=3
19 hddtemp_priority=90000
20
21 # _check is called once, to find out if this chart should be enabled or not
22 hddtemp_check() {
23     require_cmd nc || return 1
24         run nc $hddtemp_host $hddtemp_port && return 0 || return 1
25 }
26
27 # _create is called once, to create the charts
28 hddtemp_create() {
29         if [ ${#hddtemp_disks[@]} -eq 0 ]; then
30                 local all
31                 all=$(nc $hddtemp_host $hddtemp_port )
32                 unset hddtemp_disks
33                 hddtemp_disks=( `grep -Po '/dev/[^|]+' <<< "$all" | cut -c 6-` )
34         fi
35 #       local disk_names
36 #       disk_names=(`sed -e 's/||/\n/g;s/^|//' <<< "$all" | cut -d '|' -f2 | tr ' ' '_'`)
37
38         echo "CHART hddtemp.temperature 'disks_temp' 'temperature' 'Celsius' 'Disks temperature' 'hddtemp.temp' line $((hddtemp_priority)) $hddtemp_update_every"
39         for i in `seq 0 $((${#hddtemp_disks[@]}-1))`; do
40 #               echo "DIMENSION ${hddtemp_disks[i]} ${disk_names[i]} absolute 1 1"
41                 echo "DIMENSION ${hddtemp_disks[$i]} '' absolute 1 1"
42         done
43         return 0
44 }
45
46 # _update is called continiously, to collect the values
47 hddtemp_last=0
48 hddtemp_count=0
49 hddtemp_update() {
50 #        local all=( `nc $hddtemp_host $hddtemp_port | sed -e 's/||/\n/g;s/^|//' | cut -d '|' -f3` )
51 #       local all=( `nc $hddtemp_host $hddtemp_port | awk 'BEGIN { FS="|" };{i=4; while (i <= NF) {print $i+0;i+=5;};}'` )
52         OLD_IFS=$IFS
53         set -f
54         IFS="|" all=( $(nc $hddtemp_host $hddtemp_port 2>/dev/null) )
55         set +f
56         IFS=$OLD_IFS
57
58         # check if there is some data
59         if [ -z "${all[3]}" ]; then 
60                 return 1
61         fi
62
63         # write the result of the work.
64         echo "BEGIN hddtemp.temperature $1"
65         end=${#hddtemp_disks[@]}
66         for ((i=0; i<end; i++)); do
67                 # temperature - this will turn SLP to zero
68                 t=$(( ${all[ $((i * 5 + 3)) ]} ))
69                 echo "SET ${hddtemp_disks[$i]} = $t"
70         done
71         echo "END"
72
73         return 0
74 }