]> arthur.barton.de Git - netdata.git/commitdiff
added mem.apps and improved error handling and debugging for charts.d
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Sun, 4 May 2014 00:45:03 +0000 (03:45 +0300)
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Sun, 4 May 2014 00:45:03 +0000 (03:45 +0300)
charts.d/mem_apps.chart.sh [new file with mode: 0755]
charts.d/squid.chart.sh
plugins.d/charts.d.plugin
plugins.d/loopsleepms.sh.inc

diff --git a/charts.d/mem_apps.chart.sh b/charts.d/mem_apps.chart.sh
new file mode 100755 (executable)
index 0000000..cd04672
--- /dev/null
@@ -0,0 +1,60 @@
+#!/bin/sh
+
+mem_apps_apps="netdata asterisk squid apache2 mysqld dovecot cupsd sshd named clamd smbd"
+
+# these are required for computing memory in bytes and cpu in seconds
+#mem_apps_pagesize="`getconf PAGESIZE`"
+#mem_apps_clockticks="`getconf CLK_TCK`"
+
+mem_apps_check() {
+       # this should return:
+       #  - 0 to enable the chart
+       #  - 1 to disable the chart
+
+       if [ -z "$mem_apps_apps" ]
+       then
+               echo >&2 "mem_apps: Please set mem_apps_apps='command1 command2 ...' in $confd/mem_apps_apps.conf"
+               return 1
+       fi
+       return 0
+}
+
+mem_apps_bc_finalze=
+
+mem_apps_create() {
+
+       cat <<EOF1
+CHART system.apps '' "Apps Memory" "MB" "mem" "mem" stacked 20000 $update_every
+EOF1
+
+       local x=
+       for x in $mem_apps_apps
+       do
+
+cat <<EOF1
+DIMENSION $x $x absolute 1 1024
+EOF1
+               # this string is needed later in the update() function
+               # to finalize the instructions for the bc command
+               mem_apps_bc_finalze="$mem_apps_bc_finalze \"SET $x = \"; $x;"
+       done
+       return 0
+}
+
+mem_apps_egrep="(`echo "$mem_apps_apps" | sed -e "s/^ \+//g" -e "s/ \+$//g" -e "s/ /|/g"`)"
+mem_apps_update() {
+       # do all the work to collect / calculate the values
+       # for each dimension
+       # remember: KEEP IT SIMPLE AND SHORT
+
+       echo "BEGIN system.apps"
+       ps -e -o comm,rss |\
+               egrep "^$mem_apps_egrep " |\
+               (       sed -e "s/ \+/ /g" -e "s/ /+=/g";
+                       echo "$mem_apps_bc_finalze"
+               ) | bc
+       echo "END"
+
+       return 0
+}
+
index 3831c40024a6505e0acc54fb224622efd4825acd..ff584c1a974f6d6ae69f9a497e3f09bbc0fa489a 100755 (executable)
@@ -17,21 +17,21 @@ squid_check() {
 squid_create() {
        # create the charts
        cat <<EOF
-CHART squid.client_bandwidth '' "Squid Client Bandwidth" "kilobits/s" squid squid area 1 $update_every
+CHART net.squid_clients '' "Squid Client Bandwidth" "kilobits/s" squid '' area 20001 $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.client_requests '' "Squid Client Requests" "requests/s" squid squid line 3 $update_every
+CHART squid.client_requests '' "Squid Client Requests" "requests/s" squid 'none' line 20003 $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.server_bandwidth '' "Squid Server Bandwidth" "kilobits/s" squid squid area 2 $update_every
+CHART net.squid_servers '' "Squid Server Bandwidth" "kilobits/s" squid '' area 20002 $update_every
 DIMENSION server_all_kbytes_in in incremental 8 1
 DIMENSION server_all_kbytes_out out incremental -8 1
 
-CHART squid.server_requests '' "Squid Server Requests" "requests/s" squid squid line 4 $update_every
+CHART squid.server_requests '' "Squid Server Requests" "requests/s" squid 'none' line 20004 $update_every
 DIMENSION server_all_requests requests incremental 1 1
 DIMENSION server_all_errors errors incremental -1 1
 EOF
@@ -49,7 +49,7 @@ squid_update() {
 
        # write the result of the work.
        cat <<VALUESEOF
-BEGIN squid.client_bandwidth
+BEGIN net.squid_clients
 SET client_http_kbytes_in = $client_http_kbytes_in
 SET client_http_kbytes_out = $client_http_kbytes_out
 SET client_http_hit_kbytes_out = $client_http_hit_kbytes_out
@@ -61,7 +61,7 @@ SET client_http_hits = $client_http_hits
 SET client_http_errors = $client_http_errors
 END
 
-BEGIN squid.server_bandwidth
+BEGIN net.squid_servers
 SET server_all_kbytes_in = $server_all_kbytes_in
 SET server_all_kbytes_out = $server_all_kbytes_out
 END
index e10384cb617f15d416f359994a137add244d7360..453cc93321487203b95ff10fa397177881ca4b78 100755 (executable)
@@ -1,32 +1,73 @@
 #!/bin/sh
 
-check=0
-if [ "$1" = "check" ]
-then
-       check=1
-       shift
-fi
-
-# default sleep function
-loopsleepms() {
-       sleep $1
-}
-# if found and included, this file overwrites loopsleepms()
-# with a high resolution timer function for precise looping.
-. "`dirname $0`/loopsleepms.sh.inc"
-
-# netdata passes the requested update frequency as the first argument
-update_every=$1
-update_every=$(( update_every + 1 - 1))        # makes sure it is a number
-test $update_every -eq 0 && update_every=1 # if it is zero, make it 1
+# -----------------------------------------------------------------------------
+# insternal defaults
 
 pluginsd="plugins.d"
 confd="conf.d"
 chartsd="charts.d"
 myconfig="$confd/charts.d.conf"
 minimum_update_frequency=1
+update_every=1 # this is overwritten by the command line
+
+# -----------------------------------------------------------------------------
+# parse parameters
+
+debug=0
+check=0
+chart_only=
+while [ ! -z "$1" ]
+do
+       if [ "$1" = "check" ]
+       then
+               check=1
+               shift
+               continue
+       fi
+
+       if [ -f "$chartsd/$1.chart.sh" ]
+       then
+               debug=1
+               chart_only="`echo $1.chart.sh | sed "s/\.chart\.sh$//g"`"
+               shift
+               continue
+       fi
+
+       if [ -f "$chartsd/$1" ]
+       then
+               debug=1
+               chart_only="`echo $1 | sed "s/\.chart\.sh$//g"`"
+               shift
+               continue
+       fi
+
+       if [ -f "$1" ]
+       then
+               debug=1
+               chart_only="`basename "$1" | sed "s/\.chart\.sh$//g"`"
+               shift
+               continue
+       fi
+
+       # number check
+       n="$1"
+       x=$((n + 1 - 1))
+       if [ "$x" = "$n" ]
+       then
+               update_every=$x
+               shift
+               continue
+       fi
+
+       echo >&2 "Cannot understand parameter $1. Aborting."
+       echo "DISABLE"
+       exit 1
+done
+
+
+# -----------------------------------------------------------------------------
+# load my configuration
 
-# load the configuration
 if [ -f "$myconfig" ]
        then
        . "$myconfig"
@@ -38,12 +79,37 @@ if [ -f "$myconfig" ]
        fi
 fi
 
+
+# -----------------------------------------------------------------------------
+# internal checks
+
+# netdata passes the requested update frequency as the first argument
+update_every=$(( update_every + 1 - 1))        # makes sure it is a number
+test $update_every -eq 0 && update_every=1 # if it is zero, make it 1
+
+# check the charts.d directory
 if [ ! -d "$chartsd" ]
        then
        echo >&2 "charts.d: cannot find charts directory '$chartsd'"
        echo "DISABLE"
 fi
 
+
+# -----------------------------------------------------------------------------
+# loop control
+
+# default sleep function
+loopsleepms() {
+       sleep $1
+}
+# if found and included, this file overwrites loopsleepms()
+# with a high resolution timer function for precise looping.
+. "`dirname $0`/loopsleepms.sh.inc"
+
+
+# -----------------------------------------------------------------------------
+# charts check functions
+
 all_charts() {
        cd "$chartsd"
        ls *.chart.sh | sed "s/\.chart\.sh$//g"
@@ -114,6 +180,9 @@ all_enabled_charts() {
 }
 
 
+# -----------------------------------------------------------------------------
+# load the charts
+
 active_charts=
 for x in `all_enabled_charts`
 do
@@ -133,6 +202,28 @@ do
        fi
 done
 
+
+# -----------------------------------------------------------------------------
+# check overwrites
+
+# if we only need a specific chart, remove all the others
+debug_time=
+if [ ! -z "$chart_only" ]
+then
+       debug_time=tellwork
+       check_charts=
+       for x in $active_charts
+       do
+               if [ "$x" = "$chart_only" ]
+               then
+                       check_charts="$x"
+                       break
+               fi
+       done
+       active_charts="$check_charts"
+fi
+
+# stop if we just need a pre-check
 if [ $check -eq 1 ]
 then
        echo "CHECK RESULT"
@@ -140,6 +231,10 @@ then
        exit 0
 fi
 
+
+# -----------------------------------------------------------------------------
+# create charts
+
 run_charts=
 for x in $active_charts
 do
@@ -152,7 +247,9 @@ do
        fi
 done
 
-# work forever
+
+# -----------------------------------------------------------------------------
+# update dimensions
 while [ 1 ]
 do
        now_charts=$run_charts
@@ -170,5 +267,5 @@ do
        done
 
        # wait the time you are required to
-       loopsleepms $update_every
+       loopsleepms $debug_time $update_every
 done
index 3c12d5d6f3823d24bfe1b694a5fd60ec3e9d2f31..daf308a1c20df798ad08a0336b4f04e4ccc96cc4 100755 (executable)
@@ -8,7 +8,15 @@
 LOOPSLEEPMS_HIGHRES=2
 LOOPSLEEPMS_LASTRUN=0
 LOOPSLEEPMS_LASTSLEEP=0
+LOOPSLEEPMS_LASTWORK=0
 loopsleepms() {
+       tellwork=0
+       if [ "$1" = "tellwork" ]
+       then
+               local tellwork=1
+               shift
+       fi
+
        # the time in seconds to wait, as the first argument
        local t=$1
 
@@ -41,11 +49,13 @@ loopsleepms() {
        test $LOOPSLEEPMS_LASTRUN -eq 0 && LOOPSLEEPMS_LASTRUN=$now
 
        # calculate ms since last run
-       local workms=$((now - LOOPSLEEPMS_LASTRUN - LOOPSLEEPMS_LASTSLEEP))
-       # echo "# last loop's work took $workms ms"
+       LOOPSLEEPMS_LASTWORK=$((now - LOOPSLEEPMS_LASTRUN - LOOPSLEEPMS_LASTSLEEP))
+       # echo "# last loop's work took $LOOPSLEEPMS_LASTWORK ms"
+
+       test $tellwork -eq 1 && echo >&2 " >>> DEBUG >>> WORK TOOK $LOOPSLEEPMS_LASTWORK ms"
 
        # calculate ms to sleep
-       local mstosleep=$((t - workms))
+       local mstosleep=$((t - LOOPSLEEPMS_LASTWORK))
        # echo "# mstosleep is $mstosleep ms"
        
        # if we are too slow, sleep some time