From c666fc44f51dc7c488a74d90a8073de43ea93ac0 Mon Sep 17 00:00:00 2001 From: "Costa Tsaousis (ktsaou)" Date: Fri, 30 May 2014 21:21:39 +0300 Subject: [PATCH] added support for different update frequency per chart in charts.d.plugin --- charts.d/airsearches.chart.sh | 74 ++++++++++++++++++++++++++++++++++ charts.d/cpu_apps.chart.sh | 4 +- charts.d/crsproxy.chart.sh | 43 ++++++++++---------- charts.d/example.chart.sh | 4 +- charts.d/load_average.chart.sh | 4 +- charts.d/mem_apps.chart.sh | 4 +- charts.d/postfix.chart.sh | 7 ++-- charts.d/squid.chart.sh | 19 ++++----- plugins.d/charts.d.plugin | 58 ++++++++++++++++++-------- plugins.d/loopsleepms.sh.inc | 31 +++++++++++--- 10 files changed, 190 insertions(+), 58 deletions(-) create mode 100755 charts.d/airsearches.chart.sh diff --git a/charts.d/airsearches.chart.sh b/charts.d/airsearches.chart.sh new file mode 100755 index 00000000..1e4e6cd7 --- /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|
|\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 1733b7dc..735ac30b 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 6aa306a2..6d5b83b3 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 <&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 87d8bad5..2f9e097c 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 -- 2.39.2