added support for different update frequency per chart in charts.d.plugin
Costa Tsaousis (ktsaou) committed
May 30, 2014 at 21:21 UTC
c666fc44f51dc7c488a74d90a8073de43ea93ac0
10 files changed
+190
-58
charts.d/airsearches.chart.sh
new
+74
@@ -0,0 +1,74 @@
1
+#!/bin/sh
2
+
3
+airsearches_url="https://services.viva.gr/vivatravelwcf_v2/airsabre/webtesting/searchcounters.ashx"
4
+airsearches_cmds=""
5
+airsearches_update_every=60
6
+
7
+airsearches_get() {
8
+ wget 2>/dev/null -O - "$airsearches_url" |\
9
+ sed -e "s|<br />|\n|g" -e "s|: |=|g" -e "s| \+|_|g" |\
10
+ tr "[A-Z]\.\!@#\$%^&*()_+\-" "[a-z]_____________" |\
11
+ egrep "^[a-z0-9_]+=[0-9]+$" |\
12
+ sort -u
13
+}
14
+
15
+airsearches_check() {
16
+ # check once if the url works
17
+ wget 2>/dev/null -O /dev/null "$airsearches_url"
18
+ if [ ! $? -eq 0 ]
19
+ then
20
+ echo >&2 "airsearches: cannot fetch the url: $airsearches_url. Please set airsearches_url='url' in $confd/airsearches.conf"
21
+ return 1
22
+ fi
23
+
24
+ if [ -z "$airsearches_cmds" ]
25
+ then
26
+ airsearches_cmds="`airsearches_get | cut -d '=' -f 1`"
27
+ echo
28
+ fi
29
+ if [ -z "$airsearches_cmds" ]
30
+ then
31
+ echo >&2 "airsearches: cannot find command list automatically. Please set airsearches_cmds='...' in $confd/airsearches.conf"
32
+ return 1
33
+ fi
34
+ return 0
35
+}
36
+
37
+airsearches_create() {
38
+ # create the charts
39
+ local x=
40
+ echo "CHART airsearches.affiliates '' 'Air Searches per affiliate' 'requests / $airsearches_update_every secs' airsearches '' stacked 20000 $airsearches_update_every"
41
+ for x in $airsearches_cmds
42
+ do
43
+ echo "DIMENSION $x '' incremental 1 1"
44
+ done
45
+
46
+ return 0
47
+}
48
+
49
+airsearches_update() {
50
+ # the first argument to this function is the microseconds since last update
51
+ # pass this parameter to the BEGIN statement (see bellow).
52
+
53
+ # do all the work to collect / calculate the values
54
+ # for each dimension
55
+ # remember: KEEP IT SIMPLE AND SHORT
56
+
57
+ # get the values from airsearches
58
+ eval "`airsearches_get | sed "s/^/airsearches_/g"`"
59
+
60
+ # write the result of the work.
61
+ local x=
62
+
63
+ echo "BEGIN airsearches.affiliates $1"
64
+ for x in $airsearches_cmds
65
+ do
66
+ eval "v=\$airsearches_$x"
67
+ echo "SET $x = $v"
68
+ done
69
+ echo "END"
70
+
71
+ airsearches_dt=0
72
+
73
+ return 0
74
+}
charts.d/cpu_apps.chart.sh
+3
-1
@@ -6,6 +6,8 @@ cpu_apps_apps="netdata asterisk squid apache2 mysqld dovecot cupsd sshd named cl
6
#cpu_apps_pagesize="`getconf PAGESIZE`"
7
cpu_apps_clockticks="`getconf CLK_TCK`"
8
9
+cpu_apps_update_every=60
10
+
11
cpu_apps_check() {
12
# this should return:
13
# - 0 to enable the chart
@@ -23,7 +25,7 @@ cpu_apps_bc_finalze=
25
26
cpu_apps_create() {
27
26
- echo "CHART apps.cpu '' 'Apps CPU' 'milliseconds/s' apps apps stacked 20001 $update_every"
28
+ echo "CHART apps.cpu '' 'Apps CPU' 'milliseconds / $cpu_apps_update_every sec' apps apps stacked 20001 $cpu_apps_update_every"
29
30
local x=
31
for x in $cpu_apps_apps
charts.d/crsproxy.chart.sh
+22
-21
@@ -2,6 +2,7 @@
2
3
crsproxy_url="http://127.0.0.1:7999/counters?"
4
crsproxy_cmds=""
5
+crsproxy_update_every=60
6
7
crsproxy_check() {
8
# check once if the url works
@@ -28,36 +29,36 @@ crsproxy_check() {
29
crsproxy_create() {
30
# create the charts
31
cat <<EOF
31
-CHART crsproxy.connected '' "CRS Proxy Connected Clients" "clients" crsproxy '' line 20000 $update_every
32
-DIMENSION web '' absolute-no-interpolation 1 1
33
-DIMENSION native '' absolute-no-interpolation 1 1
34
-DIMENSION virtual '' absolute-no-interpolation 1 1
35
-CHART crsproxy.requests '' "CRS Proxy Requests Rate" "requests/s" crsproxy '' area 20001 $update_every
36
-DIMENSION web '' incremental-no-interpolation 1 1
37
-DIMENSION native '' incremental-no-interpolation -1 1
38
-CHART crsproxy.clients '' "CRS Proxy Clients Rate" "clients/s" crsproxy '' area 20010 $update_every
39
-DIMENSION web '' incremental-no-interpolation 1 1
40
-DIMENSION native '' incremental-no-interpolation -1 1
41
-DIMENSION virtual '' incremental-no-interpolation 1 1
42
-CHART crsproxy.replies '' "CRS Replies Rate" "replies/s" crsproxy '' area 20020 $update_every
43
-DIMENSION ok '' incremental-no-interpolation 1 1
44
-DIMENSION failed '' incremental-no-interpolation -1 1
45
-CHART crsproxy.bconnections '' "Back-End Connections Rate" "connections/s" crsproxy '' area 20030 $update_every
46
-DIMENSION ok '' incremental-no-interpolation 1 1
47
-DIMENSION failed '' incremental-no-interpolation -1 1
32
+CHART crsproxy.connected '' "CRS Proxy Connected Clients" "clients" crsproxy '' line 20000 $crsproxy_update_every
33
+DIMENSION web '' absolute 1 1
34
+DIMENSION native '' absolute 1 1
35
+DIMENSION virtual '' absolute 1 1
36
+CHART crsproxy.requests '' "CRS Proxy Requests Rate" "requests / $crsproxy_update_every sec" crsproxy '' area 20001 $crsproxy_update_every
37
+DIMENSION web '' incremental 1 1
38
+DIMENSION native '' incremental -1 1
39
+CHART crsproxy.clients '' "CRS Proxy Clients Rate" "clients / $crsproxy_update_every sec" crsproxy '' area 20010 $crsproxy_update_every
40
+DIMENSION web '' incremental 1 1
41
+DIMENSION native '' incremental -1 1
42
+DIMENSION virtual '' incremental 1 1
43
+CHART crsproxy.replies '' "CRS Replies Rate" "replies / $crsproxy_update_every sec" crsproxy '' area 20020 $crsproxy_update_every
44
+DIMENSION ok '' incremental 1 1
45
+DIMENSION failed '' incremental -1 1
46
+CHART crsproxy.bconnections '' "Back-End Connections Rate" "connections / $crsproxy_update_every sec" crsproxy '' area 20030 $crsproxy_update_every
47
+DIMENSION ok '' incremental 1 1
48
+DIMENSION failed '' incremental -1 1
49
EOF
50
51
local x=
51
- echo "CHART crsproxy.commands '' 'CRS Commands Requests' 'requests/s' crsproxy '' stacked 20100 $update_every"
52
+ echo "CHART crsproxy.commands '' 'CRS Commands Requests' 'requests / $crsproxy_update_every sec' crsproxy '' stacked 20100 $crsproxy_update_every"
53
for x in $crsproxy_cmds
54
do
54
- echo "DIMENSION $x '' incremental-no-interpolation 1 1"
55
+ echo "DIMENSION $x '' incremental 1 1"
56
done
57
57
- echo "CHART crsproxy.commands_failed '' 'CRS Failed Commands' 'replies/s' crsproxy '' stacked 20110 $update_every"
58
+ echo "CHART crsproxy.commands_failed '' 'CRS Failed Commands' 'replies / $crsproxy_update_every sec' crsproxy '' stacked 20110 $crsproxy_update_every"
59
for x in $crsproxy_cmds
60
do
60
- echo "DIMENSION $x '' incremental-no-interpolation 1 1"
61
+ echo "DIMENSION $x '' incremental 1 1"
62
done
63
64
return 0
charts.d/example.chart.sh
+3
-1
@@ -1,5 +1,7 @@
1
#!/bin/sh
2
3
+example_update_every=
4
+
5
example_check() {
6
# this should return:
7
# - 0 to enable the chart
@@ -11,7 +13,7 @@ example_check() {
13
example_create() {
14
# create the chart with 3 dimensions
15
cat <<EOF
14
-CHART example.random '' "Random Numbers Stacked Chart" "% of random numbers" random random stacked 5000 $update_every
16
+CHART example.random '' "Random Numbers Stacked Chart" "% of random numbers" random random stacked 5000 $example_update_every
17
DIMENSION random1 '' percentage-of-absolute-row 1 1
18
DIMENSION random2 '' percentage-of-absolute-row 1 1
19
DIMENSION random3 '' percentage-of-absolute-row 1 1
charts.d/load_average.chart.sh
+3
-1
@@ -1,5 +1,7 @@
1
#!/bin/sh
2
3
+load_average_update_every=
4
+
5
load_average_check() {
6
# this should return:
7
# - 0 to enable the chart
@@ -11,7 +13,7 @@ load_average_check() {
13
load_average_create() {
14
# create a chart with 3 dimensions
15
cat <<EOF
14
-CHART example.load '' "System Load Average" "load" load load line 500 $update_every
16
+CHART example.load '' "System Load Average" "load" load load line 500 $load_average_update_every
17
DIMENSION load1 '1 min' absolute 1 100
18
DIMENSION load5 '5 mins' absolute 1 100
19
DIMENSION load15 '15 mins' absolute 1 100
charts.d/mem_apps.chart.sh
+3
-1
@@ -6,6 +6,8 @@ mem_apps_apps="netdata asterisk squid apache2 mysqld dovecot cupsd sshd named cl
6
#mem_apps_pagesize="`getconf PAGESIZE`"
7
#mem_apps_clockticks="`getconf CLK_TCK`"
8
9
+mem_apps_update_every=
10
+
11
mem_apps_check() {
12
# this should return:
13
# - 0 to enable the chart
@@ -23,7 +25,7 @@ mem_apps_bc_finalze=
25
26
mem_apps_create() {
27
26
- echo "CHART apps.mem '' 'Apps Memory' MB apps apps stacked 20000 $update_every"
28
+ echo "CHART apps.mem '' 'Apps Memory' MB apps apps stacked 20000 $mem_apps_update_every"
29
30
local x=
31
for x in $mem_apps_apps
charts.d/postfix.chart.sh
+4
-3
@@ -1,6 +1,7 @@
1
#!/bin/sh
2
3
postfix_postqueue=
4
+postfix_update_every=60
5
6
postfix_check() {
7
# this should return:
@@ -36,9 +37,9 @@ postfix_check() {
37
38
postfix_create() {
39
cat <<EOF
39
-CHART postfix.qemails '' "Postfix Queue Emails" "emails" postfix postfix line 5000 $update_every
40
-DIMENSION emails '' absolute-no-interpolation 1 1
41
-CHART postfix.qsize '' "Postfix Queue Emails Size" "emails size in KB" postfix postfix area 5001 $update_every
40
+CHART postfix.qemails '' "Postfix Queue Emails" "emails" postfix postfix line 5000 $postfix_update_every
41
+DIMENSION emails '' absolute 1 1
42
+CHART postfix.qsize '' "Postfix Queue Emails Size" "emails size in KB" postfix postfix area 5001 $postfix_update_every
43
DIMENSION size '' absolute 1 1
44
EOF
45
charts.d/squid.chart.sh
+10
-9
@@ -1,6 +1,7 @@
1
#!/bin/sh
2
3
squid_url="http://127.0.0.1:8080/squid-internal-mgr/counters"
4
+squid_update_every=5
5
6
squid_check() {
7
# check once if the url works
@@ -17,23 +18,23 @@ squid_check() {
18
squid_create() {
19
# create the charts
20
cat <<EOF
20
-CHART squid.clients_net '' "Squid Client Bandwidth" "kilobits/s" squid '' area 20001 $update_every
21
+CHART squid.clients_net '' "Squid Client Bandwidth" "kilobits / $squid_update_every sec" squid '' area 20001 $squid_update_every
22
DIMENSION client_http_kbytes_in in incremental 8 1
23
DIMENSION client_http_kbytes_out out incremental -8 1
24
DIMENSION client_http_hit_kbytes_out hits incremental -8 1
25
25
-CHART squid.clients_requests '' "Squid Client Requests" "requests/s" squid '' line 20003 $update_every
26
-DIMENSION client_http_requests requests incremental-no-interpolation 1 1
27
-DIMENSION client_http_hits hits incremental-no-interpolation 1 1
28
-DIMENSION client_http_errors errors incremental-no-interpolation -1 1
26
+CHART squid.clients_requests '' "Squid Client Requests" "requests / $squid_update_every sec" squid '' line 20003 $squid_update_every
27
+DIMENSION client_http_requests requests incremental 1 1
28
+DIMENSION client_http_hits hits incremental 1 1
29
+DIMENSION client_http_errors errors incremental -1 1
30
30
-CHART squid.servers_net '' "Squid Server Bandwidth" "kilobits/s" squid '' area 20002 $update_every
31
+CHART squid.servers_net '' "Squid Server Bandwidth" "kilobits / $squid_update_every sec" squid '' area 20002 $squid_update_every
32
DIMENSION server_all_kbytes_in in incremental 8 1
33
DIMENSION server_all_kbytes_out out incremental -8 1
34
34
-CHART squid.servers_requests '' "Squid Server Requests" "requests/s" squid '' line 20004 $update_every
35
-DIMENSION server_all_requests requests incremental-no-interpolation 1 1
36
-DIMENSION server_all_errors errors incremental-no-interpolation -1 1
35
+CHART squid.servers_requests '' "Squid Server Requests" "requests / $squid_update_every sec" squid '' line 20004 $squid_update_every
36
+DIMENSION server_all_requests requests incremental 1 1
37
+DIMENSION server_all_errors errors incremental -1 1
38
EOF
39
40
return 0
plugins.d/charts.d.plugin
+42
-16
@@ -206,6 +206,7 @@ all_enabled_charts() {
206
# -----------------------------------------------------------------------------
207
# load the charts
208
209
+suffix_update_every="_update_every"
210
active_charts=
211
for chart in `all_enabled_charts`
212
do
@@ -216,6 +217,13 @@ do
217
. "$confd/$chart.conf"
218
fi
219
220
+ eval "dt=\$$chart$suffix_update_every"
221
+ dt=$(( dt + 1 - 1 )) # make sure it is a number
222
+ if [ $dt -lt $update_every ]
223
+ then
224
+ eval "$chart$suffix_update_every=$update_every"
225
+ fi
226
+
227
$chart$charts_check
228
if [ $? -eq 0 ]
229
then
@@ -275,9 +283,20 @@ done
283
284
# -----------------------------------------------------------------------------
285
# update dimensions
286
+
287
global_update() {
288
local exit_after=$((3600 / update_every))
289
290
+ # return the current time in ms in $now_ms
291
+ current_time_ms
292
+
293
+ local chart=
294
+ for chart in $now_charts
295
+ do
296
+ eval "local last_update_$chart=\$((now_ms - ($chart$suffix_update_every * 1000) ))"
297
+ done
298
+
299
+ # the main loop
300
local c=0
301
while [ 1 ]
302
do
@@ -288,27 +307,34 @@ global_update() {
307
local chart=
308
for chart in $now_charts
309
do
291
- local d="`date +'%s.%N'`"
292
- local s="`echo $d | cut -d '.' -f 1`"
293
- local m="`echo $d | cut -d '.' -f 2 | cut -b 1-3`"
294
- local now="$s$m" # milliseconds since epoch (1-1-1970)
295
-
296
- eval "local last=\$last_update_$chart"
297
- test -z "$last" && local last=$((now - 1000))
310
+ # return the current time in ms in $now_ms
311
+ current_time_ms
312
299
- local dt=$(( (now - last) * 1000 ))
300
- eval "last_update_$chart=$now"
313
+ eval "local chart_min_dt=\$$chart$suffix_update_every"
314
+ test -z "$chart_min_dt" && local chart_min_dt=$update_every
315
+ local chart_min_dt=$((chart_min_dt * 1000000))
316
302
- # the first call should not give a duration
303
- # so that netdata calibrates to current time
304
- test $c -eq 1 && local dt=
317
+ eval "local last=\$last_update_$chart"
318
+ test -z "$last" && local last=$((now_ms - (chart_min_dt / 1000) ))
319
306
- $chart$charts_update $dt
307
- if [ $? -eq 0 ]
320
+ local dt=$(( (now_ms - last) * 1000 ))
321
+ if [ $dt -ge $chart_min_dt ]
322
then
309
- run_charts="$run_charts $chart"
323
+ eval "last_update_$chart=$now_ms"
324
+
325
+ # the first call should not give a duration
326
+ # so that netdata calibrates to current time
327
+ test $c -eq 1 && local dt=
328
+
329
+ $chart$charts_update $dt
330
+ if [ $? -eq 0 ]
331
+ then
332
+ run_charts="$run_charts $chart"
333
+ else
334
+ echo >&2 "charts.d: chart '$chart' update() function reports failure. Disabling it."
335
+ fi
336
else
311
- echo >&2 "charts.d: chart '$chart' update() function reports failure. Disabling it."
337
+ run_charts="$run_charts $chart"
338
fi
339
done
340
plugins.d/loopsleepms.sh.inc
+26
-5
@@ -9,6 +9,31 @@ LOOPSLEEPMS_HIGHRES=2
9
LOOPSLEEPMS_LASTRUN=0
10
LOOPSLEEPMS_LASTSLEEP=0
11
LOOPSLEEPMS_LASTWORK=0
12
+
13
+check_high_res() {
14
+ LOOPSLEEPMS_HIGHRES=1
15
+ test `date +%N` = "%N" && LOOPSLEEPMS_HIGHRES=0
16
+}
17
+
18
+now_ms=
19
+current_time_ms() {
20
+ # check if high resolution timer is supported
21
+ test $LOOPSLEEPMS_HIGHRES -eq 2 && check_high_res
22
+
23
+ # if high resolution is not supported
24
+ # just sleep the time requested, in seconds
25
+ if [ $LOOPSLEEPMS_HIGHRES -eq 0 ]
26
+ then
27
+ local s="`date +'%s'`"
28
+ local m="000"
29
+ else
30
+ local d="`date +'%s.%N'`"
31
+ local s="`echo $d | cut -d '.' -f 1`"
32
+ local m="`echo $d | cut -d '.' -f 2 | cut -b 1-3`"
33
+ fi
34
+ now_ms="$s$m"
35
+}
36
+
37
loopsleepms() {
38
tellwork=0
39
if [ "$1" = "tellwork" ]
@@ -21,11 +46,7 @@ loopsleepms() {
46
local t=$1
47
48
# check if high resolution timer is supported
24
- if [ $LOOPSLEEPMS_HIGHRES -eq 2 ]
25
- then
26
- LOOPSLEEPMS_HIGHRES=1
27
- test `date +%N` = "%N" && LOOPSLEEPMS_HIGHRES=0
28
- fi
49
+ test $LOOPSLEEPMS_HIGHRES -eq 2 && check_high_res
50
51
# if high resolution is not supported
52
# just sleep the time requested, in seconds