@cryptotaxi247 / netdata-1 / commits / 07a21f704

added voltage and fan sensors

Costa Tsaousis (ktsaou) committed Oct 3, 2015 at 20:00 UTC 07a21f70463b82ae0d5b0163e9a657a817bb64fd
1 file changed +138
charts.d/sensors.chart.sh new
+138
@@ -0,0 +1,138 @@
1 +#!/bin/sh
2 +
3 +# if this chart is called X.chart.sh, then all functions and global variables
4 +# must start with X_
5 +
6 +# _update_every is a special variable - it holds the number of seconds
7 +# between the calls of the _update() function
8 +sensors_update_every=
9 +
10 +sensors_find_all_files() {
11 + find $1 -name temp\?_input -o -name temp -o -name in\?_input -o -name fan\?_input 2>/dev/null
12 +}
13 +
14 +sensors_find_all_dirs() {
15 + sensors_find_all_files $1 | while read
16 + do
17 + dirname $REPLY
18 + done | sort -u
19 +}
20 +
21 +# _check is called once, to find out if this chart should be enabled or not
22 +sensors_check() {
23 +
24 + # this should return:
25 + # - 0 to enable the chart
26 + # - 1 to disable the chart
27 +
28 + [ ! -z "$( sensors_find_all_files /sys/devices/ )" ] && return 0
29 + return 1
30 +}
31 +
32 +# _create is called once, to create the charts
33 +sensors_create() {
34 + local path= dir= name= x= file= lfile= labelname= labelid= device= subsystem= id= type= mode= files= multiplier= divisor=
35 +
36 + echo >$TMP_DIR/temp.sh "sensors_update() {"
37 +
38 + for path in $( sensors_find_all_dirs /sys/devices/ | sort -u )
39 + do
40 + dir=$( basename $path )
41 + device=
42 + subsystem=
43 + id=
44 + type=
45 + name=
46 +
47 + [ -h $path/device ] && device=$( readlink -f $path/device )
48 + [ ! -z "$device" ] && device=$( basename $device )
49 + [ -z "$device" ] && device="$dir"
50 +
51 + [ -h $path/subsystem ] && subsystem=$( readlink -f $path/subsystem )
52 + [ ! -z "$subsystem" ] && subsystem=$( basename $subsystem )
53 + [ -z "$subsystem" ] && subsystem="$dir"
54 +
55 + [ -f $path/name ] && name=$( cat $path/name )
56 + [ -z "$name" ] && name="$dir"
57 +
58 + [ -f $path/type ] && type=$( cat $path/type )
59 + [ -z "$type" ] && type="$dir"
60 +
61 + id="$( fixid "$device.$subsystem.$dir" )"
62 +
63 + echo >&2 "charts.d: temperature sensors on path='$path', dir='$dir', device='$device', subsystem='$subsystem', id='$id', name='$name'"
64 +
65 + for mode in temperature voltage fans
66 + do
67 + files=
68 + multiplier=1
69 + divisor=1
70 + case $mode in
71 + temperature)
72 + files="$( find $path -name temp\?_input -o -name temp | sort -u)"
73 + [ -z "$files" ] && continue
74 + echo "CHART sensors.temp_${id} '' '${name} Temperature' 'Temperature' 'Celcius Degrees' '' line 6000 $sensors_update_every"
75 + echo >>$TMP_DIR/temp.sh "echo \"BEGIN sensors.temp_${id} \$1\""
76 + divisor=1000
77 + ;;
78 +
79 + voltage)
80 + files="$( find $path -name in\?_input )"
81 + [ -z "$files" ] && continue
82 + echo "CHART sensors.volt_${id} '' '${name} Voltage' 'Voltage' 'Volts' '' line 6001 $sensors_update_every"
83 + echo >>$TMP_DIR/temp.sh "echo \"BEGIN sensors.volt_${id} \$1\""
84 + divisor=1000
85 + ;;
86 +
87 + fans)
88 + files="$( find $path -name fan\?_input )"
89 + [ -z "$files" ] && continue
90 + echo "CHART sensors.fan_${id} '' '${name} Fans Speed' 'Fans' 'Rotations Per Minute (RPM)' '' line 6002 $sensors_update_every"
91 + echo >>$TMP_DIR/temp.sh "echo \"BEGIN sensors.fan_${id} \$1\""
92 + ;;
93 +
94 + *)
95 + continue
96 + ;;
97 + esac
98 +
99 + for x in $files
100 + do
101 + file="$x"
102 + fid="$( fixid "$file" )"
103 + lfile="$( basename $file | sed "s|_input$|_label|g" )"
104 + labelname="$( basename $file )"
105 +
106 + if [ ! "$path/$lfile" = "$file" -a -f "$path/$lfile" ]
107 + then
108 + labelname="$( cat "$path/$lfile" )"
109 + fi
110 +
111 + echo "DIMENSION $fid '$labelname' absolute $multiplier $divisor"
112 + echo >>$TMP_DIR/temp.sh "printf \"SET $fid = \"; cat $file "
113 + done
114 +
115 + echo >>$TMP_DIR/temp.sh "echo END"
116 + done
117 + done
118 +
119 + echo >>$TMP_DIR/temp.sh "}"
120 + . $TMP_DIR/temp.sh
121 +
122 + return 0
123 +}
124 +
125 +# _update is called continiously, to collect the values
126 +sensors_update() {
127 + # the first argument to this function is the microseconds since last update
128 + # pass this parameter to the BEGIN statement (see bellow).
129 +
130 + # do all the work to collect / calculate the values
131 + # for each dimension
132 + # remember: KEEP IT SIMPLE AND SHORT
133 +
134 +# . $TMP_DIR/temp.sh $1
135 +
136 + return 0
137 +}
138 +