summaryrefslogtreecommitdiffstats
path: root/plugins.d
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 /plugins.d
parent4bb4aaaa10a9325373f4039419581f74fa31aa62 (diff)
added support for different update frequency per chart in charts.d.plugin
Diffstat (limited to 'plugins.d')
-rwxr-xr-xplugins.d/charts.d.plugin58
-rwxr-xr-xplugins.d/loopsleepms.sh.inc31
2 files changed, 68 insertions, 21 deletions
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