]> arthur.barton.de Git - netdata.git/blobdiff - charts.d/sensors.chart.sh
rename chart fields to avoid conflicts with backends; fixes #1962
[netdata.git] / charts.d / sensors.chart.sh
old mode 100755 (executable)
new mode 100644 (file)
index 19e9385..125c925
@@ -1,4 +1,10 @@
-#!/bin/sh
+# no need for shebang - this file is loaded from charts.d.plugin
+
+# netdata
+# real-time performance and health monitoring, done right!
+# (C) 2016 Costa Tsaousis <costa@tsaousis.gr>
+# GPL v3+
+#
 
 # sensors docs
 # https://www.kernel.org/doc/Documentation/hwmon/sysfs-interface
@@ -23,6 +29,8 @@ sensors_update_every=
 
 sensors_priority=90000
 
+declare -A sensors_excluded=()
+
 sensors_find_all_files() {
        find $1 -maxdepth $sensors_sys_depth -name \*_input -o -name temp 2>/dev/null
 }
@@ -41,23 +49,28 @@ sensors_check() {
        #  - 0 to enable the chart
        #  - 1 to disable the chart
 
-       [ -z "$( sensors_find_all_files $sensors_sys_dir )" ] && echo >&2 "$PROGRAM_NAME: sensors: no sensors found in '$sensors_sys_dir'." && return 1
+       [ -z "$( sensors_find_all_files $sensors_sys_dir )" ] && error "no sensors found in '$sensors_sys_dir'." && return 1
        return 0
 }
 
 sensors_check_files() {
        # we only need sensors that report a non-zero value
+       # also remove not needed sensors
 
-       local f= v=
+       local f= v= excluded=
        for f in $*
        do
                [ ! -f "$f" ] && continue
+               for ex in ${sensors_excluded[@]}; do
+                       [[ $f =~ .*$ex$ ]] && excluded='1' && break
+               done
 
-               v="$( cat $f )"
+               [ "$excluded" != "1" ] && v="$( cat $f )" || v=0
                v=$(( v + 1 - 1 ))
                [ $v -ne 0 ] && echo "$f" && continue
+               excluded=
 
-               echo >&2 "$PROGRAM_NAME: sensors: $f gives zero values"
+               error "$f gives zero values"
        done
 }
 
@@ -76,7 +89,7 @@ sensors_check_temp_type() {
                v=$(( v + 1 - 1 ))
                [ $v -ne 0 ] && echo "$f" && continue
 
-               echo >&2 "$PROGRAM_NAME: sensors: $f is disabled"
+               error "$f is disabled"
        done
 }
 
@@ -114,7 +127,7 @@ sensors_create() {
 
                id="$( fixid "$device.$subsystem.$dir" )"
 
-               echo >&2 "charts.d: sensors: on path='$path', dir='$dir', device='$device', subsystem='$subsystem', id='$id', name='$name'"
+               debug "path='$path', dir='$dir', device='$device', subsystem='$subsystem', id='$id', name='$name'"
 
                for mode in temperature voltage fans power current energy humidity
                do
@@ -206,7 +219,7 @@ sensors_create() {
                                fi
 
                                echo "DIMENSION $fid '$labelname' $algorithm $multiplier $divisor"
-                               echo >>$TMP_DIR/sensors.sh "printf \"SET $fid = \"; cat $file "
+                               echo >>$TMP_DIR/sensors.sh "echo \"SET $fid = \"\$(< $file )"
                        done
 
                        echo >>$TMP_DIR/sensors.sh "echo END"
@@ -214,7 +227,6 @@ sensors_create() {
        done
 
        [ $sensors_source_update -eq 1 ] && echo >>$TMP_DIR/sensors.sh "}"
-       # cat >&2 $TMP_DIR/sensors.sh
 
        # ok, load the function sensors_update() we created
        [ $sensors_source_update -eq 1 ] && . $TMP_DIR/sensors.sh