@cryptotaxi247 / netdata-1 / commits / 26ad9eaf6

support disabled sensors

Costa Tsaousis (ktsaou) committed Oct 3, 2015 at 23:01 UTC 26ad9eaf6ffe56d8ecc678cf15a3e97ad900b300
1 file changed +38 -7
charts.d/sensors.chart.sh
+38 -7
@@ -5,6 +5,7 @@
5
6 sensors_sys_dir="/sys/devices"
7 sensors_sys_depth=10
8 +sensors_source_update=1
9
10 # _update_every is a special variable - it holds the number of seconds
11 # between the calls of the _update() function
@@ -33,13 +34,37 @@ sensors_check() {
34 }
35
36 sensors_check_files() {
37 + # we only need sensors that report a non-zero value
38 +
39 local f= v=
40 for f in $*
41 do
39 - echo >&2 "checking $f"
42 + [ ! -f "$f" ] && continue
43 +
44 v="$( cat $f )"
45 v=$(( v + 1 - 1 ))
42 - [ $v -ne 0 ] && echo "$f"
46 + [ $v -ne 0 ] && echo "$f" && continue
47 +
48 + echo >&2 "charts.d: sensors: $f gives zero values"
49 + done
50 +}
51 +
52 +sensors_check_temp_type() {
53 + # valid temp types are 1 to 6
54 + # disabled sensors have the value 0
55 +
56 + local f= t= v=
57 + for f in $*
58 + do
59 + t=$( echo $f | sed "s|_input$|_type|g" )
60 + [ "$f" = "$t" ] && echo "$f" && continue
61 + [ ! -f "$t" ] && echo "$f" && continue
62 +
63 + v="$( cat $t )"
64 + v=$(( v + 1 - 1 ))
65 + [ $v -ne 0 ] && echo "$f" && continue
66 +
67 + echo >&2 "charts.d: sensors: $f is disabled"
68 done
69 }
70
@@ -47,7 +72,10 @@ sensors_check_files() {
72 sensors_create() {
73 local path= dir= name= x= file= lfile= labelname= labelid= device= subsystem= id= type= mode= files= multiplier= divisor=
74
50 - echo >$TMP_DIR/temp.sh "sensors_update() {"
75 + # we create a script with the source of the
76 + # sensors_update() function
77 + # - the highest speed we can achieve -
78 + [ $sensors_source_update -eq 1 ] && echo >$TMP_DIR/temp.sh "sensors_update() {"
79
80 for path in $( sensors_find_all_dirs $sensors_sys_dir | sort -u )
81 do
@@ -74,7 +102,7 @@ sensors_create() {
102
103 id="$( fixid "$device.$subsystem.$dir" )"
104
77 - echo >&2 "charts.d: sensors on path='$path', dir='$dir', device='$device', subsystem='$subsystem', id='$id', name='$name'"
105 + echo >&2 "charts.d: sensors: on path='$path', dir='$dir', device='$device', subsystem='$subsystem', id='$id', name='$name'"
106
107 for mode in temperature voltage fans power current energy humidity
108 do
@@ -87,6 +115,7 @@ sensors_create() {
115 temperature)
116 files="$( ls $path/temp*_input 2>/dev/null; ls $path/temp 2>/dev/null )"
117 files="$( sensors_check_files $files )"
118 + files="$( sensors_check_temp_type $files )"
119 [ -z "$files" ] && continue
120 echo "CHART sensors.temp_${id} '' '${name} Temperature' 'Celcius' '${device}' '' line 6000 $sensors_update_every"
121 echo >>$TMP_DIR/temp.sh "echo \"BEGIN sensors.temp_${id} \$1\""
@@ -173,8 +202,10 @@ sensors_create() {
202 done
203
204 echo >>$TMP_DIR/temp.sh "}"
176 - cat >&2 $TMP_DIR/temp.sh
177 - . $TMP_DIR/temp.sh
205 + # cat >&2 $TMP_DIR/temp.sh
206 +
207 + # ok, load the function sensors_update() we created
208 + [ $sensors_source_update -eq 1 ] && . $TMP_DIR/temp.sh
209
210 return 0
211 }
@@ -188,7 +219,7 @@ sensors_update() {
219 # for each dimension
220 # remember: KEEP IT SIMPLE AND SHORT
221
191 -# . $TMP_DIR/temp.sh $1
222 + [ $sensors_source_update -eq 0 ] && . $TMP_DIR/temp.sh $1
223
224 return 0
225 }