]> arthur.barton.de Git - netdata.git/blob - charts.d/cpufreq.chart.sh
added a new element on all charts: context, which is the template upon the chart...
[netdata.git] / charts.d / cpufreq.chart.sh
1 #!/bin/sh
2
3 # if this chart is called X.chart.sh, then all functions and global variables
4 # must start with X_
5
6 cpufreq_sys_dir="/sys/devices"
7 cpufreq_sys_depth=10
8 cpufreq_source_update=1
9
10 # _update_every is a special variable - it holds the number of seconds
11 # between the calls of the _update() function
12 cpufreq_update_every=
13 cpufreq_priority=10000
14
15 cpufreq_find_all_files() {
16         find $1 -maxdepth $cpufreq_sys_depth -name scaling_cur_freq 2>/dev/null
17 }
18
19 # _check is called once, to find out if this chart should be enabled or not
20 cpufreq_check() {
21
22         # this should return:
23         #  - 0 to enable the chart
24         #  - 1 to disable the chart
25
26         [ -z "$( cpufreq_find_all_files $cpufreq_sys_dir )" ] && return 1
27         return 0
28 }
29
30 # _create is called once, to create the charts
31 cpufreq_create() {
32         local dir= file= id= i=
33
34         # we create a script with the source of the
35         # cpufreq_update() function
36         # - the highest speed we can achieve -
37         [ $cpufreq_source_update -eq 1 ] && echo >$TMP_DIR/cpufreq.sh "cpufreq_update() {"
38
39         echo "CHART cpu.cpufreq '' 'CPU Clock' 'MHz' 'cpufreq' '' line $[cpufreq_priority + 1] $cpufreq_update_every"
40         echo >>$TMP_DIR/cpufreq.sh "echo \"BEGIN cpu.cpufreq \$1\""
41
42         i=0
43         for file in $( cpufreq_find_all_files $cpufreq_sys_dir | sort -u )
44         do
45                 i=$(( i + 1 ))
46                 dir=$( dirname $file )
47                 cpu=
48
49                 [ -f $dir/affected_cpus ] && cpu=$( cat $dir/affected_cpus )
50                 [ -z "$cpu" ] && cpu="$i.a"
51
52                 id="$( fixid "cpu$cpu" )"
53
54                 echo >&2 "charts.d: cpufreq: on file='$file', dir='$dir', cpu='$cpu', id='$id'"
55
56                 echo "DIMENSION $id '$id' absolute 1 1000"
57                 echo >>$TMP_DIR/cpufreq.sh "printf \"SET $id = \"; cat $file "
58         done
59         echo >>$TMP_DIR/cpufreq.sh "echo END"
60
61         [ $cpufreq_source_update -eq 1 ] && echo >>$TMP_DIR/cpufreq.sh "}"
62         # cat >&2 $TMP_DIR/cpufreq.sh
63
64         # ok, load the function cpufreq_update() we created
65         [ $cpufreq_source_update -eq 1 ] && . $TMP_DIR/cpufreq.sh
66
67         return 0
68 }
69
70 # _update is called continiously, to collect the values
71 cpufreq_update() {
72         # the first argument to this function is the microseconds since last update
73         # pass this parameter to the BEGIN statement (see bellow).
74
75         # do all the work to collect / calculate the values
76         # for each dimension
77         # remember: KEEP IT SIMPLE AND SHORT
78
79         [ $cpufreq_source_update -eq 0 ] && . $TMP_DIR/cpufreq.sh $1
80
81         return 0
82 }
83