@cryptotaxi247 / netdata-1 / commits / da3ef5f1b

updated to work on /sys/class/hwmon

Costa Tsaousis (ktsaou) committed Oct 3, 2015 at 20:26 UTC da3ef5f1bb5ad7af52acf859b39e98e811ec7788
1 file changed +12 -8
charts.d/sensors.chart.sh
+12 -8
@@ -3,12 +3,15 @@
3 # if this chart is called X.chart.sh, then all functions and global variables
4 # must start with X_
5
6 +sensors_sys_dir="/sys/class/hwmon"
7 +sensors_sys_depth=3
8 +
9 # _update_every is a special variable - it holds the number of seconds
10 # between the calls of the _update() function
11 sensors_update_every=
12
13 sensors_find_all_files() {
11 - find $1 -name temp\?_input -o -name temp -o -name in\?_input -o -name fan\?_input 2>/dev/null
14 + find -L $1 -maxdepth $sensors_sys_depth -name temp\?_input -o -name temp -o -name in\?_input -o -name fan\?_input 2>/dev/null
15 }
16
17 sensors_find_all_dirs() {
@@ -25,7 +28,7 @@ sensors_check() {
28 # - 0 to enable the chart
29 # - 1 to disable the chart
30
28 - [ ! -z "$( sensors_find_all_files /sys/devices/ )" ] && return 0
31 + [ ! -z "$( sensors_find_all_files $sensors_sys_dir )" ] && return 0
32 return 1
33 }
34
@@ -35,7 +38,7 @@ sensors_create() {
38
39 echo >$TMP_DIR/temp.sh "sensors_update() {"
40
38 - for path in $( sensors_find_all_dirs /sys/devices/ | sort -u )
41 + for path in $( sensors_find_all_dirs $sensors_sys_dir | sort -u )
42 do
43 dir=$( basename $path )
44 device=
@@ -60,7 +63,7 @@ sensors_create() {
63
64 id="$( fixid "$device.$subsystem.$dir" )"
65
63 - echo >&2 "charts.d: temperature sensors on path='$path', dir='$dir', device='$device', subsystem='$subsystem', id='$id', name='$name'"
66 + echo >&2 "charts.d: sensors on path='$path', dir='$dir', device='$device', subsystem='$subsystem', id='$id', name='$name'"
67
68 for mode in temperature voltage fans
69 do
@@ -69,7 +72,7 @@ sensors_create() {
72 divisor=1
73 case $mode in
74 temperature)
72 - files="$( find $path -name temp\?_input -o -name temp | sort -u)"
75 + files="$( find -H $path -name temp\?_input -o -name temp | sort -u)"
76 [ -z "$files" ] && continue
77 echo "CHART sensors.temp_${id} '' '${name} Temperature' 'Temperature' 'Celcius Degrees' '' line 6000 $sensors_update_every"
78 echo >>$TMP_DIR/temp.sh "echo \"BEGIN sensors.temp_${id} \$1\""
@@ -77,7 +80,7 @@ sensors_create() {
80 ;;
81
82 voltage)
80 - files="$( find $path -name in\?_input )"
83 + files="$( find -H $path -name in\?_input )"
84 [ -z "$files" ] && continue
85 echo "CHART sensors.volt_${id} '' '${name} Voltage' 'Voltage' 'Volts' '' line 6001 $sensors_update_every"
86 echo >>$TMP_DIR/temp.sh "echo \"BEGIN sensors.volt_${id} \$1\""
@@ -85,7 +88,7 @@ sensors_create() {
88 ;;
89
90 fans)
88 - files="$( find $path -name fan\?_input )"
91 + files="$( find -H $path -name fan\?_input )"
92 [ -z "$files" ] && continue
93 echo "CHART sensors.fan_${id} '' '${name} Fans Speed' 'Fans' 'Rotations Per Minute (RPM)' '' line 6002 $sensors_update_every"
94 echo >>$TMP_DIR/temp.sh "echo \"BEGIN sensors.fan_${id} \$1\""
@@ -101,7 +104,7 @@ sensors_create() {
104 file="$x"
105 fid="$( fixid "$file" )"
106 lfile="$( basename $file | sed "s|_input$|_label|g" )"
104 - labelname="$( basename $file )"
107 + labelname="$( basename $file | sed "s|_input$||g" )"
108
109 if [ ! "$path/$lfile" = "$file" -a -f "$path/$lfile" ]
110 then
@@ -117,6 +120,7 @@ sensors_create() {
120 done
121
122 echo >>$TMP_DIR/temp.sh "}"
123 + cat >&2 $TMP_DIR/temp.sh
124 . $TMP_DIR/temp.sh
125
126 return 0