]> arthur.barton.de Git - netdata.git/commitdiff
added cpu_apps chart
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Sun, 4 May 2014 12:52:54 +0000 (15:52 +0300)
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Sun, 4 May 2014 12:52:54 +0000 (15:52 +0300)
charts.d/cpu_apps.chart.sh [new file with mode: 0755]
plugins.d/charts.d.plugin

diff --git a/charts.d/cpu_apps.chart.sh b/charts.d/cpu_apps.chart.sh
new file mode 100755 (executable)
index 0000000..1733b7d
--- /dev/null
@@ -0,0 +1,60 @@
+#!/bin/sh
+
+cpu_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
+#cpu_apps_pagesize="`getconf PAGESIZE`"
+cpu_apps_clockticks="`getconf CLK_TCK`"
+
+cpu_apps_check() {
+       # this should return:
+       #  - 0 to enable the chart
+       #  - 1 to disable the chart
+
+       if [ -z "$cpu_apps_apps" ]
+       then
+               echo >&2 "cpu_apps: Please set cpu_apps_apps='command1 command2 ...' in $confd/cpu_apps_apps.conf"
+               return 1
+       fi
+       return 0
+}
+
+cpu_apps_bc_finalze=
+
+cpu_apps_create() {
+
+       echo "CHART apps.cpu '' 'Apps CPU' 'milliseconds/s' apps apps stacked 20001 $update_every"
+
+       local x=
+       for x in $cpu_apps_apps
+       do
+               echo "DIMENSION $x $x incremental 1000 $cpu_apps_clockticks"
+
+               # this string is needed later in the update() function
+               # to finalize the instructions for the bc command
+               cpu_apps_bc_finalze="$cpu_apps_bc_finalze \"SET $x = \"; $x;"
+       done
+       return 0
+}
+
+cpu_apps_update() {
+       # do all the work to collect / calculate the values
+       # for each dimension
+       # remember: KEEP IT SIMPLE AND SHORT
+
+       echo "BEGIN apps.cpu"
+       ps -o pid,comm -C "$cpu_apps_apps" |\
+               grep -v "COMMAND" |\
+               (
+                       while read pid name
+                       do
+                               echo "$name+=`cat /proc/$pid/stat | cut -d ' ' -f 14-15`"
+                       done
+               ) |\
+               (       sed -e "s/ \+/ /g" -e "s/ /+/g";
+                       echo "$cpu_apps_bc_finalze"
+               ) | bc
+       echo "END"
+
+       return 0
+}
index 453cc93321487203b95ff10fa397177881ca4b78..310402824034dae9b2e2076b8fb6919f6202ebe4 100755 (executable)
@@ -25,6 +25,13 @@ do
                continue
        fi
 
+       if [ "$1" = "debug" -o "$1" = "all" ]
+       then
+               debug=1
+               shift
+               continue
+       fi
+
        if [ -f "$chartsd/$1.chart.sh" ]
        then
                debug=1
@@ -206,11 +213,13 @@ done
 # -----------------------------------------------------------------------------
 # check overwrites
 
-# if we only need a specific chart, remove all the others
+# enable work time reporting
 debug_time=
+test $debug -eq 1 && debug_time=tellwork
+
+# if we only need a specific chart, remove all the others
 if [ ! -z "$chart_only" ]
 then
-       debug_time=tellwork
        check_charts=
        for x in $active_charts
        do