3 # if this chart is called X.chart.sh, then all functions and global variables
6 sensors_sys_dir="/sys/class/hwmon"
9 # _update_every is a special variable - it holds the number of seconds
10 # between the calls of the _update() function
13 sensors_find_all_files() {
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
17 sensors_find_all_dirs() {
18 sensors_find_all_files $1 | while read
24 # _check is called once, to find out if this chart should be enabled or not
28 # - 0 to enable the chart
29 # - 1 to disable the chart
31 [ ! -z "$( sensors_find_all_files $sensors_sys_dir )" ] && return 0
35 # _create is called once, to create the charts
37 local path= dir= name= x= file= lfile= labelname= labelid= device= subsystem= id= type= mode= files= multiplier= divisor=
39 echo >$TMP_DIR/temp.sh "sensors_update() {"
41 for path in $( sensors_find_all_dirs $sensors_sys_dir | sort -u )
43 dir=$( basename $path )
50 [ -h $path/device ] && device=$( readlink -f $path/device )
51 [ ! -z "$device" ] && device=$( basename $device )
52 [ -z "$device" ] && device="$dir"
54 [ -h $path/subsystem ] && subsystem=$( readlink -f $path/subsystem )
55 [ ! -z "$subsystem" ] && subsystem=$( basename $subsystem )
56 [ -z "$subsystem" ] && subsystem="$dir"
58 [ -f $path/name ] && name=$( cat $path/name )
59 [ -z "$name" ] && name="$dir"
61 [ -f $path/type ] && type=$( cat $path/type )
62 [ -z "$type" ] && type="$dir"
64 id="$( fixid "$device.$subsystem.$dir" )"
66 echo >&2 "charts.d: sensors on path='$path', dir='$dir', device='$device', subsystem='$subsystem', id='$id', name='$name'"
68 for mode in temperature voltage fans
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\""
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\""
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\""
105 fid="$( fixid "$file" )"
106 lfile="$( basename $file | sed "s|_input$|_label|g" )"
107 labelname="$( basename $file | sed "s|_input$||g" )"
109 if [ ! "$path/$lfile" = "$file" -a -f "$path/$lfile" ]
111 labelname="$( cat "$path/$lfile" )"
114 echo "DIMENSION $fid '$labelname' absolute $multiplier $divisor"
115 echo >>$TMP_DIR/temp.sh "printf \"SET $fid = \"; cat $file "
118 echo >>$TMP_DIR/temp.sh "echo END"
122 echo >>$TMP_DIR/temp.sh "}"
123 cat >&2 $TMP_DIR/temp.sh
129 # _update is called continiously, to collect the values
131 # the first argument to this function is the microseconds since last update
132 # pass this parameter to the BEGIN statement (see bellow).
134 # do all the work to collect / calculate the values
136 # remember: KEEP IT SIMPLE AND SHORT
138 # . $TMP_DIR/temp.sh $1