]> arthur.barton.de Git - netdata.git/commitdiff
added support for different update frequency per chart in charts.d.plugin
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Fri, 30 May 2014 18:21:39 +0000 (21:21 +0300)
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Fri, 30 May 2014 18:21:39 +0000 (21:21 +0300)
charts.d/airsearches.chart.sh [new file with mode: 0755]
charts.d/cpu_apps.chart.sh
charts.d/crsproxy.chart.sh
charts.d/example.chart.sh
charts.d/load_average.chart.sh
charts.d/mem_apps.chart.sh
charts.d/postfix.chart.sh
charts.d/squid.chart.sh
plugins.d/charts.d.plugin
plugins.d/loopsleepms.sh.inc

diff --git a/charts.d/airsearches.chart.sh b/charts.d/airsearches.chart.sh
new file mode 100755 (executable)
index 0000000..1e4e6cd
--- /dev/null
@@ -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
+}
index 1733b7dce4061911ead8b5a0f94740faa0af36a1..735ac30b3e1399d12ec99881178441e68e846095 100755 (executable)
@@ -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
index 6aa306a234c1e32711bce95666b36b1a6d77d9db..6d5b83b30a50d16b39615a3f60794e6ed5a391c0 100755 (executable)
@@ -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
index 369769c11dc5b86d0812ad913fa42f71a8bd20ad..0f6251ad803380152dd84b015eca6d53845594f1 100755 (executable)
@@ -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
index e2c72494a9191b9ec4b6dec6b8b757ecc7dddded..6e5d5e05728aceabe6c68125645354d60dc8d78f 100755 (executable)
@@ -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
index 75618d748ea17ceea76fe62d3568c9a56f5b3724..3afa4ad325536c62cf05c1e6cdee9c5c9b7ff457 100755 (executable)
@@ -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
index 413296222480ed6de85a97ad7dc5bc9d3df5d14f..e55ca15906d201f35008271e594566fbcc05e55f 100755 (executable)
@@ -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
 
index f1d958b6880dfeebfca2654e99e1e528bbc08168..a9bcea2a5d42f4ce30278cf1740168820c8a976a 100755 (executable)
@@ -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
index 3127fd3edaa4020ddf6dc497ff08e0dd3e529ddc..a747378f6cbb1ba343fc7bc2141313593054ae27 100755 (executable)
@@ -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
 
index 87d8bad583988d05e508c1d112ef8f82d8d24704..2f9e097c41a63e3cce346439c64d40478ee0845e 100755 (executable)
@@ -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