diff options
author | Costa Tsaousis (ktsaou) <costa@tsaousis.gr> | 2015-10-03 21:28:44 +0300 |
---|---|---|
committer | Costa Tsaousis (ktsaou) <costa@tsaousis.gr> | 2015-10-03 21:28:44 +0300 |
commit | df1913cea2e08a9a02ecb623bec218cec546de3f (patch) | |
tree | 1eeb4ffd5ad422b94182b4931616aa5c789002bf /charts.d/sensors.chart.sh | |
parent | da3ef5f1bb5ad7af52acf859b39e98e811ec7788 (diff) |
added all possible sensors (temperature, voltage, current, energy, power, humidity, fans)
Diffstat (limited to 'charts.d/sensors.chart.sh')
-rwxr-xr-x | charts.d/sensors.chart.sh | 75 |
1 files changed, 64 insertions, 11 deletions
diff --git a/charts.d/sensors.chart.sh b/charts.d/sensors.chart.sh index a70c7c49ca..a527c9340a 100755 --- a/charts.d/sensors.chart.sh +++ b/charts.d/sensors.chart.sh @@ -3,15 +3,15 @@ # if this chart is called X.chart.sh, then all functions and global variables # must start with X_ -sensors_sys_dir="/sys/class/hwmon" -sensors_sys_depth=3 +sensors_sys_dir="/sys/devices" +sensors_sys_depth=10 # _update_every is a special variable - it holds the number of seconds # between the calls of the _update() function sensors_update_every= sensors_find_all_files() { - find -L $1 -maxdepth $sensors_sys_depth -name temp\?_input -o -name temp -o -name in\?_input -o -name fan\?_input 2>/dev/null + find $1 -maxdepth $sensors_sys_depth -name \*_input -o -name temp 2>/dev/null } sensors_find_all_dirs() { @@ -32,6 +32,17 @@ sensors_check() { return 1 } +sensors_check_files() { + local f= v= + for f in $* + do + echo >&2 "checking $f" + v="$( cat $f )" + v=$(( v + 1 - 1 )) + [ $v -ne 0 ] && echo "$f" + done +} + # _create is called once, to create the charts sensors_create() { local path= dir= name= x= file= lfile= labelname= labelid= device= subsystem= id= type= mode= files= multiplier= divisor= @@ -65,35 +76,77 @@ sensors_create() { echo >&2 "charts.d: sensors on path='$path', dir='$dir', device='$device', subsystem='$subsystem', id='$id', name='$name'" - for mode in temperature voltage fans + for mode in temperature voltage fans power current energy humidity do files= multiplier=1 divisor=1 + algorithm="absolute" + case $mode in temperature) - files="$( find -H $path -name temp\?_input -o -name temp | sort -u)" + files="$( ls $path/temp*_input 2>/dev/null; ls $path/temp 2>/dev/null )" + files="$( sensors_check_files $files )" [ -z "$files" ] && continue - echo "CHART sensors.temp_${id} '' '${name} Temperature' 'Temperature' 'Celcius Degrees' '' line 6000 $sensors_update_every" + echo "CHART sensors.temp_${id} '' '${name} Temperature' 'Celcius' '${device}' '' line 6000 $sensors_update_every" echo >>$TMP_DIR/temp.sh "echo \"BEGIN sensors.temp_${id} \$1\"" divisor=1000 ;; voltage) - files="$( find -H $path -name in\?_input )" + files="$( ls $path/in*_input 2>/dev/null )" + files="$( sensors_check_files $files )" [ -z "$files" ] && continue - echo "CHART sensors.volt_${id} '' '${name} Voltage' 'Voltage' 'Volts' '' line 6001 $sensors_update_every" + echo "CHART sensors.volt_${id} '' '${name} Voltage' 'Volts' '${device}' '' line 6001 $sensors_update_every" echo >>$TMP_DIR/temp.sh "echo \"BEGIN sensors.volt_${id} \$1\"" divisor=1000 ;; + current) + files="$( ls $path/curr*_input 2>/dev/null )" + files="$( sensors_check_files $files )" + [ -z "$files" ] && continue + echo "CHART sensors.curr_${id} '' '${name} Current' 'Ampere' '${device}' '' line 6002 $sensors_update_every" + echo >>$TMP_DIR/temp.sh "echo \"BEGIN sensors.curr_${id} \$1\"" + divisor=1000 + ;; + + power) + files="$( ls $path/power*_input 2>/dev/null )" + files="$( sensors_check_files $files )" + [ -z "$files" ] && continue + echo "CHART sensors.power_${id} '' '${name} Power' 'Watt' '${device}' '' line 6003 $sensors_update_every" + echo >>$TMP_DIR/temp.sh "echo \"BEGIN sensors.power_${id} \$1\"" + divisor=1000000 + ;; + fans) - files="$( find -H $path -name fan\?_input )" + files="$( ls $path/fan*_input 2>/dev/null )" + files="$( sensors_check_files $files )" [ -z "$files" ] && continue - echo "CHART sensors.fan_${id} '' '${name} Fans Speed' 'Fans' 'Rotations Per Minute (RPM)' '' line 6002 $sensors_update_every" + echo "CHART sensors.fan_${id} '' '${name} Fans Speed' 'Rotations / Minute' '${device}' '' line 6004 $sensors_update_every" echo >>$TMP_DIR/temp.sh "echo \"BEGIN sensors.fan_${id} \$1\"" ;; + emergy) + files="$( ls $path/energy*_input 2>/dev/null )" + files="$( sensors_check_files $files )" + [ -z "$files" ] && continue + echo "CHART sensors.energy_${id} '' '${name} Energy' 'Joule' '${device}' '' areastack 6005 $sensors_update_every" + echo >>$TMP_DIR/temp.sh "echo \"BEGIN sensors.energy_${id} \$1\"" + algorithm="incremental" + divisor=1000000 + ;; + + humidity) + files="$( ls $path/humidity*_input 2>/dev/null )" + files="$( sensors_check_files $files )" + [ -z "$files" ] && continue + echo "CHART sensors.humidity_${id} '' '${name} Humidity' 'Percent' '${device}' '' line 6006 $sensors_update_every" + echo >>$TMP_DIR/temp.sh "echo \"BEGIN sensors.humidity_${id} \$1\"" + divisor=1000 + ;; + *) continue ;; @@ -111,7 +164,7 @@ sensors_create() { labelname="$( cat "$path/$lfile" )" fi - echo "DIMENSION $fid '$labelname' absolute $multiplier $divisor" + echo "DIMENSION $fid '$labelname' $algorithm $multiplier $divisor" echo >>$TMP_DIR/temp.sh "printf \"SET $fid = \"; cat $file " done |