@cryptotaxi247 / netdata-1 / commits / 48c7f0f69

fixed minor issues in sensors.chart.sh; added cpufreq.chart.sh; removed obsolete pi.chart.sh

Costa Tsaousis (ktsaou) committed Oct 4, 2015 at 14:26 UTC 48c7f0f69ccf2a374c6a2f22b62bc4f289b3ab0b
4 files changed +105 -66
README.md
+2 -1
@@ -90,7 +90,8 @@ Here is a screenshot:
90 - `charts.d.plugin` provides a simple way to script data collection in BASH. It includes example plugins that collect values from:
91
92 - `nut` (UPS load, frequency, voltage, etc)
93 - - `pi` (raspberry pi CPU clock and temperature)
93 + - `sensors` (read temperature, voltage, current, power, humidity, fans rotation sensors)
94 + - `cpufreq` (read current CPU clock frequency)
95 - `postfix` (e-mail queue size)
96 - `squid` (web proxy statistics)
97
charts.d/cpufreq.chart.sh new
+82
@@ -0,0 +1,82 @@
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 +
14 +cpufreq_find_all_files() {
15 + find $1 -maxdepth $cpufreq_sys_depth -name scaling_cur_freq 2>/dev/null
16 +}
17 +
18 +# _check is called once, to find out if this chart should be enabled or not
19 +cpufreq_check() {
20 +
21 + # this should return:
22 + # - 0 to enable the chart
23 + # - 1 to disable the chart
24 +
25 + [ ! -z "$( cpufreq_find_all_files $cpufreq_sys_dir )" ] && return 0
26 + return 1
27 +}
28 +
29 +# _create is called once, to create the charts
30 +cpufreq_create() {
31 + local dir= file= id= i=
32 +
33 + # we create a script with the source of the
34 + # cpufreq_update() function
35 + # - the highest speed we can achieve -
36 + [ $cpufreq_source_update -eq 1 ] && echo >$TMP_DIR/cpufreq.sh "cpufreq_update() {"
37 +
38 + echo "CHART sensors.cpufreq '' 'CPU Clock' 'MHz' 'cpufreq' '' line 7000 $cpufreq_update_every"
39 + echo >>$TMP_DIR/cpufreq.sh "echo \"BEGIN sensors.cpufreq \$1\""
40 +
41 + i=0
42 + for file in $( cpufreq_find_all_files $cpufreq_sys_dir | sort -u )
43 + do
44 + i=$(( i + 1 ))
45 + dir=$( dirname $file )
46 + cpu=
47 +
48 + [ -f $dir/affected_cpus ] && cpu=$( cat $dir/affected_cpus )
49 + [ -z "$cpu" ] && cpu="$i.a"
50 +
51 + id="$( fixid "cpu$cpu" )"
52 +
53 + echo >&2 "charts.d: cpufreq: on file='$file', dir='$dir', cpu='$cpu', id='$id'"
54 +
55 + echo "DIMENSION $id '$id' absolute 1 1000"
56 + echo >>$TMP_DIR/cpufreq.sh "printf \"SET $id = \"; cat $file "
57 + done
58 + echo >>$TMP_DIR/cpufreq.sh "echo END"
59 +
60 + [ $cpufreq_source_update -eq 1 ] && echo >>$TMP_DIR/cpufreq.sh "}"
61 + # cat >&2 $TMP_DIR/cpufreq.sh
62 +
63 + # ok, load the function cpufreq_update() we created
64 + [ $cpufreq_source_update -eq 1 ] && . $TMP_DIR/cpufreq.sh
65 +
66 + return 0
67 +}
68 +
69 +# _update is called continiously, to collect the values
70 +cpufreq_update() {
71 + # the first argument to this function is the microseconds since last update
72 + # pass this parameter to the BEGIN statement (see bellow).
73 +
74 + # do all the work to collect / calculate the values
75 + # for each dimension
76 + # remember: KEEP IT SIMPLE AND SHORT
77 +
78 + [ $cpufreq_source_update -eq 0 ] && . $TMP_DIR/cpufreq.sh $1
79 +
80 + return 0
81 +}
82 +
charts.d/pi.chart.sh deleted
-44
@@ -1,44 +0,0 @@
1 -#!/bin/sh
2 -
3 -pi_update_every=1
4 -
5 -pi_check() {
6 - return 0
7 -}
8 -
9 -pi_create() {
10 - # create the charts
11 - cat <<EOF
12 -CHART pi.cpu_temp '' "Pi CPU Temperature" "Celcius degrees" pi '' line 30001 $pi_update_every
13 -DIMENSION cpu_temp cpu absolute 1 1000
14 -CHART pi.clock '' "Pi CPU Clock" "MHz" pi '' line 30003 $pi_update_every
15 -DIMENSION cpu_clock clock absolute 1 1000
16 -EOF
17 - return 0
18 -}
19 -
20 -
21 -pi_update() {
22 - # the first argument to this function is the microseconds since last update
23 - # pass this parameter to the BEGIN statement (see bellow).
24 -
25 - # do all the work to collect / calculate the values
26 - # for each dimension
27 - # remember: KEEP IT SIMPLE AND SHORT
28 -
29 - local cpuTemp=$(cat /sys/class/thermal/thermal_zone0/temp)
30 - local cpuSpeed=$(cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq)
31 -
32 - # write the result of the work.
33 - cat <<VALUESEOF
34 -BEGIN pi.cpu_temp $1
35 -SET cpu_temp = $cpuTemp
36 -END
37 -BEGIN pi.clock $1
38 -SET cpu_clock = $cpuSpeed
39 -END
40 -
41 -VALUESEOF
42 -
43 - return 0
44 -}
charts.d/sensors.chart.sh
+21 -21
@@ -78,7 +78,7 @@ sensors_create() {
78 # we create a script with the source of the
79 # sensors_update() function
80 # - the highest speed we can achieve -
81 - [ $sensors_source_update -eq 1 ] && echo >$TMP_DIR/temp.sh "sensors_update() {"
81 + [ $sensors_source_update -eq 1 ] && echo >$TMP_DIR/sensors.sh "sensors_update() {"
82
83 for path in $( sensors_find_all_dirs $sensors_sys_dir | sort -u )
84 do
@@ -120,8 +120,8 @@ sensors_create() {
120 files="$( sensors_check_files $files )"
121 files="$( sensors_check_temp_type $files )"
122 [ -z "$files" ] && continue
123 - echo "CHART sensors.temp_${id} '' '${name} Temperature' 'Celcius' '${device}' '' line 6000 $sensors_update_every"
124 - echo >>$TMP_DIR/temp.sh "echo \"BEGIN sensors.temp_${id} \$1\""
123 + echo "CHART sensors.temp_$id '' '$name Temperature' 'Celcius' '$device' '' line 6000 $sensors_update_every"
124 + echo >>$TMP_DIR/sensors.sh "echo \"BEGIN sensors.temp_$id \$1\""
125 divisor=1000
126 ;;
127
@@ -129,8 +129,8 @@ sensors_create() {
129 files="$( ls $path/in*_input 2>/dev/null )"
130 files="$( sensors_check_files $files )"
131 [ -z "$files" ] && continue
132 - echo "CHART sensors.volt_${id} '' '${name} Voltage' 'Volts' '${device}' '' line 6001 $sensors_update_every"
133 - echo >>$TMP_DIR/temp.sh "echo \"BEGIN sensors.volt_${id} \$1\""
132 + echo "CHART sensors.volt_$id '' '$name Voltage' 'Volts' '$device' '' line 6001 $sensors_update_every"
133 + echo >>$TMP_DIR/sensors.sh "echo \"BEGIN sensors.volt_$id \$1\""
134 divisor=1000
135 ;;
136
@@ -138,8 +138,8 @@ sensors_create() {
138 files="$( ls $path/curr*_input 2>/dev/null )"
139 files="$( sensors_check_files $files )"
140 [ -z "$files" ] && continue
141 - echo "CHART sensors.curr_${id} '' '${name} Current' 'Ampere' '${device}' '' line 6002 $sensors_update_every"
142 - echo >>$TMP_DIR/temp.sh "echo \"BEGIN sensors.curr_${id} \$1\""
141 + echo "CHART sensors.curr_$id '' '$name Current' 'Ampere' '$device' '' line 6002 $sensors_update_every"
142 + echo >>$TMP_DIR/sensors.sh "echo \"BEGIN sensors.curr_$id \$1\""
143 divisor=1000
144 ;;
145
@@ -147,8 +147,8 @@ sensors_create() {
147 files="$( ls $path/power*_input 2>/dev/null )"
148 files="$( sensors_check_files $files )"
149 [ -z "$files" ] && continue
150 - echo "CHART sensors.power_${id} '' '${name} Power' 'Watt' '${device}' '' line 6003 $sensors_update_every"
151 - echo >>$TMP_DIR/temp.sh "echo \"BEGIN sensors.power_${id} \$1\""
150 + echo "CHART sensors.power_$id '' '$name Power' 'Watt' '$device' '' line 6003 $sensors_update_every"
151 + echo >>$TMP_DIR/sensors.sh "echo \"BEGIN sensors.power_$id \$1\""
152 divisor=1000000
153 ;;
154
@@ -156,16 +156,16 @@ sensors_create() {
156 files="$( ls $path/fan*_input 2>/dev/null )"
157 files="$( sensors_check_files $files )"
158 [ -z "$files" ] && continue
159 - echo "CHART sensors.fan_${id} '' '${name} Fans Speed' 'Rotations / Minute' '${device}' '' line 6004 $sensors_update_every"
160 - echo >>$TMP_DIR/temp.sh "echo \"BEGIN sensors.fan_${id} \$1\""
159 + echo "CHART sensors.fan_$id '' '$name Fans Speed' 'Rotations / Minute' '$device' '' line 6004 $sensors_update_every"
160 + echo >>$TMP_DIR/sensors.sh "echo \"BEGIN sensors.fan_$id \$1\""
161 ;;
162
163 emergy)
164 files="$( ls $path/energy*_input 2>/dev/null )"
165 files="$( sensors_check_files $files )"
166 [ -z "$files" ] && continue
167 - echo "CHART sensors.energy_${id} '' '${name} Energy' 'Joule' '${device}' '' areastack 6005 $sensors_update_every"
168 - echo >>$TMP_DIR/temp.sh "echo \"BEGIN sensors.energy_${id} \$1\""
167 + echo "CHART sensors.energy_$id '' '$name Energy' 'Joule' '$device' '' areastack 6005 $sensors_update_every"
168 + echo >>$TMP_DIR/sensors.sh "echo \"BEGIN sensors.energy_$id \$1\""
169 algorithm="incremental"
170 divisor=1000000
171 ;;
@@ -174,8 +174,8 @@ sensors_create() {
174 files="$( ls $path/humidity*_input 2>/dev/null )"
175 files="$( sensors_check_files $files )"
176 [ -z "$files" ] && continue
177 - echo "CHART sensors.humidity_${id} '' '${name} Humidity' 'Percent' '${device}' '' line 6006 $sensors_update_every"
178 - echo >>$TMP_DIR/temp.sh "echo \"BEGIN sensors.humidity_${id} \$1\""
177 + echo "CHART sensors.humidity_$id '' '$name Humidity' 'Percent' '$device' '' line 6006 $sensors_update_every"
178 + echo >>$TMP_DIR/sensors.sh "echo \"BEGIN sensors.humidity_$id \$1\""
179 divisor=1000
180 ;;
181
@@ -197,18 +197,18 @@ sensors_create() {
197 fi
198
199 echo "DIMENSION $fid '$labelname' $algorithm $multiplier $divisor"
200 - echo >>$TMP_DIR/temp.sh "printf \"SET $fid = \"; cat $file "
200 + echo >>$TMP_DIR/sensors.sh "printf \"SET $fid = \"; cat $file "
201 done
202
203 - echo >>$TMP_DIR/temp.sh "echo END"
203 + echo >>$TMP_DIR/sensors.sh "echo END"
204 done
205 done
206
207 - echo >>$TMP_DIR/temp.sh "}"
208 - # cat >&2 $TMP_DIR/temp.sh
207 + [ $cpufreq_source_update -eq 1 ] && echo >>$TMP_DIR/sensors.sh "}"
208 + # cat >&2 $TMP_DIR/sensors.sh
209
210 # ok, load the function sensors_update() we created
211 - [ $sensors_source_update -eq 1 ] && . $TMP_DIR/temp.sh
211 + [ $sensors_source_update -eq 1 ] && . $TMP_DIR/sensors.sh
212
213 return 0
214 }
@@ -222,7 +222,7 @@ sensors_update() {
222 # for each dimension
223 # remember: KEEP IT SIMPLE AND SHORT
224
225 - [ $sensors_source_update -eq 0 ] && . $TMP_DIR/temp.sh $1
225 + [ $sensors_source_update -eq 0 ] && . $TMP_DIR/sensors.sh $1
226
227 return 0
228 }