]> arthur.barton.de Git - netdata.git/commitdiff
fixed minor issues in sensors.chart.sh; added cpufreq.chart.sh; removed obsolete...
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Sun, 4 Oct 2015 11:26:52 +0000 (14:26 +0300)
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Sun, 4 Oct 2015 11:26:52 +0000 (14:26 +0300)
README.md
charts.d/cpufreq.chart.sh [new file with mode: 0755]
charts.d/pi.chart.sh [deleted file]
charts.d/sensors.chart.sh

index d4bad9eddf0d1163497504e64289e50202402729..6beeb4801bb094d392c70c11cb91e6f009169769 100755 (executable)
--- a/README.md
+++ b/README.md
@@ -90,7 +90,8 @@ Here is a screenshot:
  - `charts.d.plugin` provides a simple way to script data collection in BASH. It includes example plugins that collect values from:
 
     - `nut` (UPS load, frequency, voltage, etc)
-    - `pi` (raspberry pi CPU clock and temperature)
+    - `sensors` (read temperature, voltage, current, power, humidity, fans rotation sensors)
+    - `cpufreq` (read current CPU clock frequency)
     - `postfix` (e-mail queue size)
     - `squid` (web proxy statistics)
 
diff --git a/charts.d/cpufreq.chart.sh b/charts.d/cpufreq.chart.sh
new file mode 100755 (executable)
index 0000000..083a7ed
--- /dev/null
@@ -0,0 +1,82 @@
+#!/bin/sh
+
+# if this chart is called X.chart.sh, then all functions and global variables
+# must start with X_
+
+cpufreq_sys_dir="/sys/devices"
+cpufreq_sys_depth=10
+cpufreq_source_update=1
+
+# _update_every is a special variable - it holds the number of seconds
+# between the calls of the _update() function
+cpufreq_update_every=
+
+cpufreq_find_all_files() {
+       find $1 -maxdepth $cpufreq_sys_depth -name scaling_cur_freq 2>/dev/null
+}
+
+# _check is called once, to find out if this chart should be enabled or not
+cpufreq_check() {
+
+       # this should return:
+       #  - 0 to enable the chart
+       #  - 1 to disable the chart
+
+       [ ! -z "$( cpufreq_find_all_files $cpufreq_sys_dir )" ] && return 0
+       return 1
+}
+
+# _create is called once, to create the charts
+cpufreq_create() {
+       local dir= file= id= i=
+
+       # we create a script with the source of the
+       # cpufreq_update() function
+       # - the highest speed we can achieve -
+       [ $cpufreq_source_update -eq 1 ] && echo >$TMP_DIR/cpufreq.sh "cpufreq_update() {"
+
+       echo "CHART sensors.cpufreq '' 'CPU Clock' 'MHz' 'cpufreq' '' line 7000 $cpufreq_update_every"
+       echo >>$TMP_DIR/cpufreq.sh "echo \"BEGIN sensors.cpufreq \$1\""
+
+       i=0
+       for file in $( cpufreq_find_all_files $cpufreq_sys_dir | sort -u )
+       do
+               i=$(( i + 1 ))
+               dir=$( dirname $file )
+               cpu=
+
+               [ -f $dir/affected_cpus ] && cpu=$( cat $dir/affected_cpus )
+               [ -z "$cpu" ] && cpu="$i.a"
+
+               id="$( fixid "cpu$cpu" )"
+
+               echo >&2 "charts.d: cpufreq: on file='$file', dir='$dir', cpu='$cpu', id='$id'"
+
+               echo "DIMENSION $id '$id' absolute 1 1000"
+               echo >>$TMP_DIR/cpufreq.sh "printf \"SET $id = \"; cat $file "
+       done
+       echo >>$TMP_DIR/cpufreq.sh "echo END"
+
+       [ $cpufreq_source_update -eq 1 ] && echo >>$TMP_DIR/cpufreq.sh "}"
+       # cat >&2 $TMP_DIR/cpufreq.sh
+
+       # ok, load the function cpufreq_update() we created
+       [ $cpufreq_source_update -eq 1 ] && . $TMP_DIR/cpufreq.sh
+
+       return 0
+}
+
+# _update is called continiously, to collect the values
+cpufreq_update() {
+       # the first argument to this function is the microseconds since last update
+       # pass this parameter to the BEGIN statement (see bellow).
+
+       # do all the work to collect / calculate the values
+       # for each dimension
+       # remember: KEEP IT SIMPLE AND SHORT
+
+       [ $cpufreq_source_update -eq 0 ] && . $TMP_DIR/cpufreq.sh $1
+
+       return 0
+}
+
diff --git a/charts.d/pi.chart.sh b/charts.d/pi.chart.sh
deleted file mode 100755 (executable)
index 1d55aa9..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-#!/bin/sh
-
-pi_update_every=1
-
-pi_check() {
-       return 0
-}
-
-pi_create() {
-       # create the charts
-       cat <<EOF
-CHART pi.cpu_temp '' "Pi CPU Temperature" "Celcius degrees" pi '' line 30001 $pi_update_every
-DIMENSION cpu_temp cpu absolute 1 1000
-CHART pi.clock '' "Pi CPU Clock" "MHz" pi '' line 30003 $pi_update_every
-DIMENSION cpu_clock clock absolute 1 1000
-EOF
-       return 0
-}
-
-
-pi_update() {
-       # the first argument to this function is the microseconds since last update
-       # pass this parameter to the BEGIN statement (see bellow).
-
-       # do all the work to collect / calculate the values
-       # for each dimension
-       # remember: KEEP IT SIMPLE AND SHORT
-
-       local cpuTemp=$(cat /sys/class/thermal/thermal_zone0/temp)
-       local cpuSpeed=$(cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq)
-
-       # write the result of the work.
-       cat <<VALUESEOF
-BEGIN pi.cpu_temp $1
-SET cpu_temp = $cpuTemp
-END
-BEGIN pi.clock $1
-SET cpu_clock = $cpuSpeed
-END
-
-VALUESEOF
-
-       return 0
-}
index c46ba323ab19a1bd37876ddf470830cdd5e314cc..f637b48182516d765fb36bcc526b453409319597 100755 (executable)
@@ -78,7 +78,7 @@ sensors_create() {
        # we create a script with the source of the
        # sensors_update() function
        # - the highest speed we can achieve -
-       [ $sensors_source_update -eq 1 ] && echo >$TMP_DIR/temp.sh "sensors_update() {"
+       [ $sensors_source_update -eq 1 ] && echo >$TMP_DIR/sensors.sh "sensors_update() {"
 
        for path in $( sensors_find_all_dirs $sensors_sys_dir | sort -u )
        do
@@ -120,8 +120,8 @@ sensors_create() {
                                        files="$( sensors_check_files $files )"
                                        files="$( sensors_check_temp_type $files )"
                                        [ -z "$files" ] && continue
-                                       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\""
+                                       echo "CHART sensors.temp_$id '' '$name Temperature' 'Celcius' '$device' '' line 6000 $sensors_update_every"
+                                       echo >>$TMP_DIR/sensors.sh "echo \"BEGIN sensors.temp_$id \$1\""
                                        divisor=1000
                                        ;;
 
@@ -129,8 +129,8 @@ sensors_create() {
                                        files="$( ls $path/in*_input 2>/dev/null )"
                                        files="$( sensors_check_files $files )"
                                        [ -z "$files" ] && continue
-                                       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\""
+                                       echo "CHART sensors.volt_$id '' '$name Voltage' 'Volts' '$device' '' line 6001 $sensors_update_every"
+                                       echo >>$TMP_DIR/sensors.sh "echo \"BEGIN sensors.volt_$id \$1\""
                                        divisor=1000
                                        ;;
 
@@ -138,8 +138,8 @@ sensors_create() {
                                        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\""
+                                       echo "CHART sensors.curr_$id '' '$name Current' 'Ampere' '$device' '' line 6002 $sensors_update_every"
+                                       echo >>$TMP_DIR/sensors.sh "echo \"BEGIN sensors.curr_$id \$1\""
                                        divisor=1000
                                        ;;
 
@@ -147,8 +147,8 @@ sensors_create() {
                                        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\""
+                                       echo "CHART sensors.power_$id '' '$name Power' 'Watt' '$device' '' line 6003 $sensors_update_every"
+                                       echo >>$TMP_DIR/sensors.sh "echo \"BEGIN sensors.power_$id \$1\""
                                        divisor=1000000
                                        ;;
 
@@ -156,16 +156,16 @@ sensors_create() {
                                        files="$( ls $path/fan*_input 2>/dev/null )"
                                        files="$( sensors_check_files $files )"
                                        [ -z "$files" ] && continue
-                                       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\""
+                                       echo "CHART sensors.fan_$id '' '$name Fans Speed' 'Rotations / Minute' '$device' '' line 6004 $sensors_update_every"
+                                       echo >>$TMP_DIR/sensors.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\""
+                                       echo "CHART sensors.energy_$id '' '$name Energy' 'Joule' '$device' '' areastack 6005 $sensors_update_every"
+                                       echo >>$TMP_DIR/sensors.sh "echo \"BEGIN sensors.energy_$id \$1\""
                                        algorithm="incremental"
                                        divisor=1000000
                                        ;;
@@ -174,8 +174,8 @@ sensors_create() {
                                        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\""
+                                       echo "CHART sensors.humidity_$id '' '$name Humidity' 'Percent' '$device' '' line 6006 $sensors_update_every"
+                                       echo >>$TMP_DIR/sensors.sh "echo \"BEGIN sensors.humidity_$id \$1\""
                                        divisor=1000
                                        ;;
 
@@ -197,18 +197,18 @@ sensors_create() {
                                fi
 
                                echo "DIMENSION $fid '$labelname' $algorithm $multiplier $divisor"
-                               echo >>$TMP_DIR/temp.sh "printf \"SET $fid = \"; cat $file "
+                               echo >>$TMP_DIR/sensors.sh "printf \"SET $fid = \"; cat $file "
                        done
 
-                       echo >>$TMP_DIR/temp.sh "echo END"
+                       echo >>$TMP_DIR/sensors.sh "echo END"
                done
        done
 
-       echo >>$TMP_DIR/temp.sh "}"
-       # cat >&2 $TMP_DIR/temp.sh
+       [ $cpufreq_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/temp.sh
+       [ $sensors_source_update -eq 1 ] && . $TMP_DIR/sensors.sh
 
        return 0
 }
@@ -222,7 +222,7 @@ sensors_update() {
        # for each dimension
        # remember: KEEP IT SIMPLE AND SHORT
 
-       [ $sensors_source_update -eq 0 ] && . $TMP_DIR/temp.sh $1
+       [ $sensors_source_update -eq 0 ] && . $TMP_DIR/sensors.sh $1
 
        return 0
 }