summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>2014-05-30 21:21:39 +0300
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>2014-05-30 21:21:39 +0300
commitc666fc44f51dc7c488a74d90a8073de43ea93ac0 (patch)
tree211d0a1a4a7feb3b8540419a33d03a3f6b4baad1
parent4bb4aaaa10a9325373f4039419581f74fa31aa62 (diff)
added support for different update frequency per chart in charts.d.plugin
-rwxr-xr-xcharts.d/airsearches.chart.sh74
-rwxr-xr-xcharts.d/cpu_apps.chart.sh4
-rwxr-xr-xcharts.d/crsproxy.chart.sh43
-rwxr-xr-xcharts.d/example.chart.sh4
-rwxr-xr-xcharts.d/load_average.chart.sh4
-rwxr-xr-xcharts.d/mem_apps.chart.sh4
-rwxr-xr-xcharts.d/postfix.chart.sh7
-rwxr-xr-xcharts.d/squid.chart.sh19
-rwxr-xr-xplugins.d/charts.d.plugin58
-rwxr-xr-xplugins.d/loopsleepms.sh.inc31
10 files changed, 190 insertions, 58 deletions
diff --git a/charts.d/airsearches.chart.sh b/charts.d/airsearches.chart.sh
new file mode 100755
index 0000000000..1e4e6cd74c
--- /dev/null
+++ b/charts.d/airsearches.chart.sh
@@ -0,0 +1,74 @@
+#!/bin/sh
+
+airsearches_url="https://services.viva.gr/vivatravelwcf_v2/airsabre/webtesting/searchcounters.ashx"
+airsearches_cmds=""
+airsearches_update_every=60
+
+airsearches_get() {
+ wget 2>/dev/null -O - "$airsearches_url" |\
+ sed -e "s|<br />|\n|g" -e "s|: |=|g" -e "s| \+|_|g" |\
+ tr "[A-Z]\.\!@#\$%^&*()_+\-" "[a-z]_____________" |\
+ egrep "^[a-z0-9_]+=[0-9]+$" |\
+ sort -u
+}
+
+airsearches_check() {
+ # check once if the url works
+ wget 2>/dev/null -O /dev/null "$airsearches_url"
+ if [ ! $? -eq 0 ]
+ then
+ echo >&2 "airsearches: cannot fetch the url: $airsearches_url. Please set airsearches_url='url' in $confd/airsearches.conf"
+ return 1
+ fi
+
+ if [ -z "$airsearches_cmds" ]
+ then
+ airsearches_cmds="`airsearches_get | cut -d '=' -f 1`"
+ echo
+ fi
+ if [ -z "$airsearches_cmds" ]
+ then
+ echo >&2 "airsearches: cannot find command list automatically. Please set airsearches_cmds='...' in $confd/airsearches.conf"
+ return 1
+ fi
+ return 0
+}
+
+airsearches_create() {
+ # create the charts
+ local x=
+ echo "CHART airsearches.affiliates '' 'Air Searches per affiliate' 'requests / $airsearches_update_every secs' airsearches '' stacked 20000 $airsearches_update_every"
+ for x in $airsearches_cmds
+ do
+ echo "DIMENSION $x '' incremental 1 1"
+ done
+
+ return 0
+}
+
+airsearches_update() {
+ # the first argument to this function is the microseconds since last update
+ # pass this parameter to the BEGIN statement (see bellow).
+
+ # do all the work to collect / calculate the values
+ # for each dimension
+ # remember: KEEP IT SIMPLE AND SHORT
+
+ # get the values from airsearches
+ eval "`airsearches_get | sed "s/^/airsearches_/g"`"
+
+ # write the result of the work.
+ local x=
+
+ echo "BEGIN airsearches.affiliates $1"
+ for x in $airsearches_cmds
+ do
+ eval "v=\$airsearches_$x"
+ echo "SET $x = $v"
+ done
+ echo "END"
+
+ airsearches_dt=0
+
+ return 0
+}
diff --git a/charts.d/cpu_apps.chart.sh b/charts.d/cpu_apps.chart.sh
index 1733b7dce4..735ac30b3e 100755
--- a/charts.d/cpu_apps.chart.sh
+++ b/charts.d/cpu_apps.chart.sh
@@ -6,6 +6,8 @@ cpu_apps_apps="netdata asterisk squid apache2 mysqld dovecot cupsd sshd named cl
#cpu_apps_pagesize="`getconf PAGESIZE`"
cpu_apps_clockticks="`getconf CLK_TCK`"
+cpu_apps_update_every=60
+
cpu_apps_check() {
# this should return:
# - 0 to enable the chart
@@ -23,7 +25,7 @@ cpu_apps_bc_finalze=
cpu_apps_create() {
- echo "CHART apps.cpu '' 'Apps CPU' 'milliseconds/s' apps apps stacked 20001 $update_every"
+ echo "CHART apps.cpu '' 'Apps CPU' 'milliseconds / $cpu_apps_update_every sec' apps apps stacked 20001 $cpu_apps_update_every"
local x=
for x in $cpu_apps_apps
diff --git a/charts.d/crsproxy.chart.sh b/charts.d/crsproxy.chart.sh
index 6aa306a234..6d5b83b30a 100755
--- a/charts.d/crsproxy.chart.sh
+++ b/charts.d/crsproxy.chart.sh
@@ -2,6 +2,7 @@
crsproxy_url="http://127.0.0.1:7999/counters?"
crsproxy_cmds=""
+crsproxy_update_every=60
crsproxy_check() {
# check once if the url works
@@ -28,36 +29,36 @@ crsproxy_check() {
crsproxy_create() {
# create the charts
cat <<EOF
-CHART crsproxy.connected '' "CRS Proxy Connected Clients" "clients" crsproxy '' line 20000 $update_every
-DIMENSION web '' absolute-no-interpolation 1 1
-DIMENSION native '' absolute-no-interpolation 1 1
-DIMENSION virtual '' absolute-no-interpolation 1 1
-CHART crsproxy.requests '' "CRS Proxy Requests Rate" "requests/s" crsproxy '' area 20001 $update_every
-DIMENSION web '' incremental-no-interpolation 1 1
-DIMENSION native '' incremental-no-interpolation -1 1
-CHART crsproxy.clients '' "CRS Proxy Clients Rate" "clients/s" crsproxy '' area 20010 $update_every
-DIMENSION web '' incremental-no-interpolation 1 1
-DIMENSION native '' incremental-no-interpolation -1 1
-DIMENSION virtual '' incremental-no-interpolation 1 1
-CHART crsproxy.replies '' "CRS Replies Rate" "replies/s" crsproxy '' area 20020 $update_every
-DIMENSION ok '' incremental-no-interpolation 1 1
-DIMENSION failed '' incremental-no-interpolation -1 1
-CHART crsproxy.bconnections '' "Back-End Connections Rate" "connections/s" crsproxy '' area 20030 $update_every
-DIMENSION ok '' incremental-no-interpolation 1 1
-DIMENSION failed '' incremental-no-interpolation -1 1
+CHART crsproxy.connected '' "CRS Proxy Connected Clients" "clients" crsproxy '' line 20000 $crsproxy_update_every
+DIMENSION web '' absolute 1 1
+DIMENSION native '' absolute 1 1
+DIMENSION virtual '' absolute 1 1
+CHART crsproxy.requests '' "CRS Proxy Requests Rate" "requests / $crsproxy_update_every sec" crsproxy '' area 20001 $crsproxy_update_every
+DIMENSION web '' incremental 1 1
+DIMENSION native '' incremental -1 1
+CHART crsproxy.clients '' "CRS Proxy Clients Rate" "clients / $crsproxy_update_every sec" crsproxy '' area 20010 $crsproxy_update_every
+DIMENSION web '' incremental 1 1
+DIMENSION native '' incremental -1 1
+DIMENSION virtual '' incremental 1 1
+CHART crsproxy.replies '' "CRS Replies Rate" "replies / $crsproxy_update_every sec" crsproxy '' area 20020 $crsproxy_update_every
+DIMENSION ok '' incremental 1 1
+DIMENSION failed '' incremental -1 1
+CHART crsproxy.bconnections '' "Back-End Connections Rate" "connections / $crsproxy_update_every sec" crsproxy '' area 20030 $crsproxy_update_every
+DIMENSION ok '' incremental 1 1
+DIMENSION failed '' incremental -1 1
EOF
local x=
- echo "CHART crsproxy.commands '' 'CRS Commands Requests' 'requests/s' crsproxy '' stacked 20100 $update_every"
+ echo "CHART crsproxy.commands '' 'CRS Commands Requests' 'requests / $crsproxy_update_every sec' crsproxy '' stacked 20100 $crsproxy_update_every"
for x in $crsproxy_cmds
do
- echo "DIMENSION $x '' incremental-no-interpolation 1 1"
+ echo "DIMENSION $x '' incremental 1 1"
done
- echo "CHART crsproxy.commands_failed '' 'CRS Failed Commands' 'replies/s' crsproxy '' stacked 20110 $update_every"
+ echo "CHART crsproxy.commands_failed '' 'CRS Failed Commands' 'replies / $crsproxy_update_every sec' crsproxy '' stacked 20110 $crsproxy_update_every"
for x in $crsproxy_cmds
do
- echo "DIMENSION $x '' incremental-no-interpolation 1 1"
+ echo "DIMENSION $x '' incremental 1 1"
done
return 0
diff --git a/charts.d/example.chart.sh b/charts.d/example.chart.sh
index 369769c11d..0f6251ad80 100755
--- a/charts.d/example.chart.sh
+++ b/charts.d/example.chart.sh
@@ -1,5 +1,7 @@
#!/bin/sh
+example_update_every=
+
example_check() {
# this should return:
# - 0 to enable the chart
@@ -11,7 +13,7 @@ example_check() {
example_create() {
# create the chart with 3 dimensions
cat <<EOF
-CHART example.random '' "Random Numbers Stacked Chart" "% of random numbers" random random stacked 5000 $update_every
+CHART example.random '' "Random Numbers Stacked Chart" "% of random numbers" random random stacked 5000 $example_update_every
DIMENSION random1 '' percentage-of-absolute-row 1 1
DIMENSION random2 '' percentage-of-absolute-row 1 1
DIMENSION random3 '' percentage-of-absolute-row 1 1
diff --git a/charts.d/load_average.chart.sh b/charts.d/load_average.chart.sh
index e2c72494a9..6e5d5e0572 100755
--- a/charts.d/load_average.chart.sh
+++ b/charts.d/load_average.chart.sh
@@ -1,5 +1,7 @@
#!/bin/sh
+load_average_update_every=
+
load_average_check() {
# this should return:
# - 0 to enable the chart
@@ -11,7 +13,7 @@ load_average_check() {
load_average_create() {
# create a chart with 3 dimensions
cat <<EOF
-CHART example.load '' "System Load Average" "load" load load line 500 $update_every
+CHART example.load '' "System Load Average" "load" load load line 500 $load_average_update_every
DIMENSION load1 '1 min' absolute 1 100
DIMENSION load5 '5 mins' absolute 1 100
DIMENSION load15 '15 mins' absolute 1 100
diff --git a/charts.d/mem_apps.chart.sh b/charts.d/mem_apps.chart.sh
index 75618d748e..3afa4ad325 100755
--- a/charts.d/mem_apps.chart.sh
+++ b/charts.d/mem_apps.chart.sh
@@ -6,6 +6,8 @@ mem_apps_apps="netdata asterisk squid apache2 mysqld dovecot cupsd sshd named cl
#mem_apps_pagesize="`getconf PAGESIZE`"
#mem_apps_clockticks="`getconf CLK_TCK`"
+mem_apps_update_every=
+
mem_apps_check() {
# this should return:
# - 0 to enable the chart
@@ -23,7 +25,7 @@ mem_apps_bc_finalze=
mem_apps_create() {
- echo "CHART apps.mem '' 'Apps Memory' MB apps apps stacked 20000 $update_every"
+ echo "CHART apps.mem '' 'Apps Memory' MB apps apps stacked 20000 $mem_apps_update_every"
local x=
for x in $mem_apps_apps
diff --git a/charts.d/postfix.chart.sh b/charts.d/postfix.chart.sh
index 4132962224..e55ca15906 100755
--- a/charts.d/postfix.chart.sh
+++ b/charts.d/postfix.chart.sh
@@ -1,6 +1,7 @@
#!/bin/sh
postfix_postqueue=
+postfix_update_every=60
postfix_check() {
# this should return:
@@ -36,9 +37,9 @@ postfix_check() {
postfix_create() {
cat <<EOF
-CHART postfix.qemails '' "Postfix Queue Emails" "emails" postfix postfix line 5000 $update_every
-DIMENSION emails '' absolute-no-interpolation 1 1
-CHART postfix.qsize '' "Postfix Queue Emails Size" "emails size in KB" postfix postfix area 5001 $update_every
+CHART postfix.qemails '' "Postfix Queue Emails" "emails" postfix postfix line 5000 $postfix_update_every
+DIMENSION emails '' absolute 1 1
+CHART postfix.qsize '' "Postfix Queue Emails Size" "emails size in KB" postfix postfix area 5001 $postfix_update_every
DIMENSION size '' absolute 1 1
EOF
diff --git a/charts.d/squid.chart.sh b/charts.d/squid.chart.sh
index f1d958b688..a9bcea2a5d 100755
--- a/charts.d/squid.chart.sh
+++ b/charts.d/squid.chart.sh
@@ -1,6 +1,7 @@
#!/bin/sh
squid_url="http://127.0.0.1:8080/squid-internal-mgr/counters"
+squid_update_every=5
squid_check() {
# check once if the url works
@@ -17,23 +18,23 @@ squid_check() {
squid_create() {
# create the charts
cat <<EOF
-CHART squid.clients_net '' "Squid Client Bandwidth" "kilobits/s" squid '' area 20001 $update_every
+CHART squid.clients_net '' "Squid Client Bandwidth" "kilobits / $squid_update_every sec" squid '' area 20001 $squid_update_every
DIMENSION client_http_kbytes_in in incremental 8 1
DIMENSION client_http_kbytes_out out incremental -8 1
DIMENSION client_http_hit_kbytes_out hits incremental -8 1
-CHART squid.clients_requests '' "Squid Client Requests" "requests/s" squid '' line 20003 $update_every
-DIMENSION client_http_requests requests incremental-no-interpolation 1 1
-DIMENSION client_http_hits hits incremental-no-interpolation 1 1
-DIMENSION client_http_errors errors incremental-no-interpolation -1 1
+CHART squid.clients_requests '' "Squid Client Requests" "requests / $squid_update_every sec" squid '' line 20003 $squid_update_every
+DIMENSION client_http_requests requests incremental 1 1
+DIMENSION client_http_hits hits incremental 1 1
+DIMENSION client_http_errors errors incremental -1 1
-CHART squid.servers_net '' "Squid Server Bandwidth" "kilobits/s" squid '' area 20002 $update_every
+CHART squid.servers_net '' "Squid Server Bandwidth" "kilobits / $squid_update_every sec" squid '' area 20002 $squid_update_every
DIMENSION server_all_kbytes_in in incremental 8 1
DIMENSION server_all_kbytes_out out incremental -8 1
-CHART squid.servers_requests '' "Squid Server Requests" "requests/s" squid '' line 20004 $update_every
-DIMENSION server_all_requests requests incremental-no-interpolation 1 1
-DIMENSION server_all_errors errors incremental-no-interpolation -1 1
+CHART squid.servers_requests '' "Squid Server Requests" "requests / $squid_update_every sec" squid '' line 20004 $squid_update_every
+DIMENSION server_all_requests requests incremental 1 1
+DIMENSION server_all_errors errors incremental -1 1
EOF
return 0
diff --git a/plugins.d/charts.d.plugin b/plugins.d/charts.d.plugin
index 3127fd3eda..a747378f6c 100755
--- a/plugins.d/charts.d.plugin
+++ b/plugins.d/charts.d.plugin
@@ -206,6 +206,7 @@ all_enabled_charts() {
# -----------------------------------------------------------------------------
# load the charts
+suffix_update_every="_update_every"
active_charts=
for chart in `all_enabled_charts`
do
@@ -216,6 +217,13 @@ do
. "$confd/$chart.conf"
fi
+ eval "dt=\$$chart$suffix_update_every"
+ dt=$(( dt + 1 - 1 )) # make sure it is a number
+ if [ $dt -lt $update_every ]
+ then
+ eval "$chart$suffix_update_every=$update_every"
+ fi
+
$chart$charts_check
if [ $? -eq 0 ]
then
@@ -275,9 +283,20 @@ done
# -----------------------------------------------------------------------------
# update dimensions
+
global_update() {
local exit_after=$((3600 / update_every))
+ # return the current time in ms in $now_ms
+ current_time_ms
+
+ local chart=
+ for chart in $now_charts
+ do
+ eval "local last_update_$chart=\$((now_ms - ($chart$suffix_update_every * 1000) ))"
+ done
+
+ # the main loop
local c=0
while [ 1 ]
do
@@ -288,27 +307,34 @@ global_update() {
local chart=
for chart in $now_charts
do
- local d="`date +'%s.%N'`"
- local s="`echo $d | cut -d '.' -f 1`"
- local m="`echo $d | cut -d '.' -f 2 | cut -b 1-3`"
- local now="$s$m" # milliseconds since epoch (1-1-1970)
-
- eval "local last=\$last_update_$chart"
- test -z "$last" && local last=$((now - 1000))
+ # return the current time in ms in $now_ms
+ current_time_ms
- local dt=$(( (now - last) * 1000 ))
- eval "last_update_$chart=$now"
+ eval "local chart_min_dt=\$$chart$suffix_update_every"
+ test -z "$chart_min_dt" && local chart_min_dt=$update_every
+ local chart_min_dt=$((chart_min_dt * 1000000))
- # the first call should not give a duration
- # so that netdata calibrates to current time
- test $c -eq 1 && local dt=
+ eval "local last=\$last_update_$chart"
+ test -z "$last" && local last=$((now_ms - (chart_min_dt / 1000) ))
- $chart$charts_update $dt
- if [ $? -eq 0 ]
+ local dt=$(( (now_ms - last) * 1000 ))
+ if [ $dt -ge $chart_min_dt ]
then
- run_charts="$run_charts $chart"
+ eval "last_update_$chart=$now_ms"
+
+ # the first call should not give a duration
+ # so that netdata calibrates to current time
+ test $c -eq 1 && local dt=
+
+ $chart$charts_update $dt
+ if [ $? -eq 0 ]
+ then
+ run_charts="$run_charts $chart"
+ else
+ echo >&2 "charts.d: chart '$chart' update() function reports failure. Disabling it."
+ fi
else
- echo >&2 "charts.d: chart '$chart' update() function reports failure. Disabling it."
+ run_charts="$run_charts $chart"
fi
done
diff --git a/plugins.d/loopsleepms.sh.inc b/plugins.d/loopsleepms.sh.inc
index 87d8bad583..2f9e097c41 100755
--- a/plugins.d/loopsleepms.sh.inc
+++ b/plugins.d/loopsleepms.sh.inc
@@ -9,6 +9,31 @@ LOOPSLEEPMS_HIGHRES=2
LOOPSLEEPMS_LASTRUN=0
LOOPSLEEPMS_LASTSLEEP=0
LOOPSLEEPMS_LASTWORK=0
+
+check_high_res() {
+ LOOPSLEEPMS_HIGHRES=1
+ test `date +%N` = "%N" && LOOPSLEEPMS_HIGHRES=0
+}
+
+now_ms=
+current_time_ms() {
+ # check if high resolution timer is supported
+ test $LOOPSLEEPMS_HIGHRES -eq 2 && check_high_res
+
+ # if high resolution is not supported
+ # just sleep the time requested, in seconds
+ if [ $LOOPSLEEPMS_HIGHRES -eq 0 ]
+ then
+ local s="`date +'%s'`"
+ local m="000"
+ else
+ local d="`date +'%s.%N'`"
+ local s="`echo $d | cut -d '.' -f 1`"
+ local m="`echo $d | cut -d '.' -f 2 | cut -b 1-3`"
+ fi
+ now_ms="$s$m"
+}
+
loopsleepms() {
tellwork=0
if [ "$1" = "tellwork" ]
@@ -21,11 +46,7 @@ loopsleepms() {
local t=$1
# check if high resolution timer is supported
- if [ $LOOPSLEEPMS_HIGHRES -eq 2 ]
- then
- LOOPSLEEPMS_HIGHRES=1
- test `date +%N` = "%N" && LOOPSLEEPMS_HIGHRES=0
- fi
+ test $LOOPSLEEPMS_HIGHRES -eq 2 && check_high_res
# if high resolution is not supported
# just sleep the time requested, in seconds