1 # no need for shebang - this file is loaded from charts.d.plugin
4 # real-time performance and health monitoring, done right!
5 # (C) 2016 Costa Tsaousis <costa@tsaousis.gr>
9 # if this chart is called X.chart.sh, then all functions and global variables
12 cpufreq_sys_dir="${NETDATA_HOST_PREFIX}/sys/devices"
14 cpufreq_source_update=1
16 # _update_every is a special variable - it holds the number of seconds
17 # between the calls of the _update() function
19 cpufreq_priority=10000
21 cpufreq_find_all_files() {
22 find $1 -maxdepth $cpufreq_sys_depth -name scaling_cur_freq 2>/dev/null
25 # _check is called once, to find out if this chart should be enabled or not
29 # - 0 to enable the chart
30 # - 1 to disable the chart
32 [ -z "$( cpufreq_find_all_files $cpufreq_sys_dir )" ] && return 1
36 # _create is called once, to create the charts
38 local dir= file= id= i=
40 # we create a script with the source of the
41 # cpufreq_update() function
42 # - the highest speed we can achieve -
43 [ $cpufreq_source_update -eq 1 ] && echo >$TMP_DIR/cpufreq.sh "cpufreq_update() {"
45 echo "CHART cpu.cpufreq '' 'CPU Clock' 'MHz' 'cpufreq' '' line $((cpufreq_priority + 1)) $cpufreq_update_every"
46 echo >>$TMP_DIR/cpufreq.sh "echo \"BEGIN cpu.cpufreq \$1\""
49 for file in $( cpufreq_find_all_files $cpufreq_sys_dir | sort -u )
52 dir=$( dirname $file )
55 [ -f $dir/affected_cpus ] && cpu=$( cat $dir/affected_cpus )
56 [ -z "$cpu" ] && cpu="$i.a"
58 id="$( fixid "cpu$cpu" )"
60 debug "file='$file', dir='$dir', cpu='$cpu', id='$id'"
62 echo "DIMENSION $id '$id' absolute 1 1000"
63 echo >>$TMP_DIR/cpufreq.sh "echo \"SET $id = \"\$(< $file )"
65 echo >>$TMP_DIR/cpufreq.sh "echo END"
67 [ $cpufreq_source_update -eq 1 ] && echo >>$TMP_DIR/cpufreq.sh "}"
69 # ok, load the function cpufreq_update() we created
70 [ $cpufreq_source_update -eq 1 ] && . $TMP_DIR/cpufreq.sh
75 # _update is called continiously, to collect the values
77 # the first argument to this function is the microseconds since last update
78 # pass this parameter to the BEGIN statement (see bellow).
80 # do all the work to collect / calculate the values
82 # remember: KEEP IT SIMPLE AND SHORT
84 [ $cpufreq_source_update -eq 0 ] && . $TMP_DIR/cpufreq.sh $1