]> arthur.barton.de Git - netdata.git/blobdiff - charts.d/cpufreq.chart.sh
ab-debian 0.20170327.01-0ab1, upstream v1.6.0-42-gaa6b96fc
[netdata.git] / charts.d / cpufreq.chart.sh
old mode 100755 (executable)
new mode 100644 (file)
index 083a7ed..b21504a
@@ -1,15 +1,22 @@
-#!/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+
+#
 
 # 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_dir="${NETDATA_HOST_PREFIX}/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_priority=10000
 
 cpufreq_find_all_files() {
        find $1 -maxdepth $cpufreq_sys_depth -name scaling_cur_freq 2>/dev/null
@@ -22,8 +29,8 @@ cpufreq_check() {
        #  - 0 to enable the chart
        #  - 1 to disable the chart
 
-       [ ! -z "$( cpufreq_find_all_files $cpufreq_sys_dir )" ] && return 0
-       return 1
+       [ -z "$( cpufreq_find_all_files $cpufreq_sys_dir )" ] && return 1
+       return 0
 }
 
 # _create is called once, to create the charts
@@ -35,8 +42,8 @@ cpufreq_create() {
        # - 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\""
+       echo "CHART cpu.cpufreq '' 'CPU Clock' 'MHz' 'cpufreq' '' line $((cpufreq_priority + 1)) $cpufreq_update_every"
+       echo >>$TMP_DIR/cpufreq.sh "echo \"BEGIN cpu.cpufreq \$1\""
 
        i=0
        for file in $( cpufreq_find_all_files $cpufreq_sys_dir | sort -u )
@@ -50,15 +57,14 @@ cpufreq_create() {
 
                id="$( fixid "cpu$cpu" )"
 
-               echo >&2 "charts.d: cpufreq: on file='$file', dir='$dir', cpu='$cpu', id='$id'"
+               debug "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 "
+               echo >>$TMP_DIR/cpufreq.sh "echo \"SET $id = \"\$(< $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