@cryptotaxi247 / netdata-1 / commits / 539c437d6

added cpu_apps chart

Costa Tsaousis (ktsaou) committed May 4, 2014 at 15:52 UTC 539c437d672f3854d2b3e5f9cabd14482f4701bc
2 files changed +71 -2
charts.d/cpu_apps.chart.sh new
+60
@@ -0,0 +1,60 @@
1 +#!/bin/sh
2 +
3 +cpu_apps_apps="netdata asterisk squid apache2 mysqld dovecot cupsd sshd named clamd smbd"
4 +
5 +# these are required for computing memory in bytes and cpu in seconds
6 +#cpu_apps_pagesize="`getconf PAGESIZE`"
7 +cpu_apps_clockticks="`getconf CLK_TCK`"
8 +
9 +cpu_apps_check() {
10 + # this should return:
11 + # - 0 to enable the chart
12 + # - 1 to disable the chart
13 +
14 + if [ -z "$cpu_apps_apps" ]
15 + then
16 + echo >&2 "cpu_apps: Please set cpu_apps_apps='command1 command2 ...' in $confd/cpu_apps_apps.conf"
17 + return 1
18 + fi
19 + return 0
20 +}
21 +
22 +cpu_apps_bc_finalze=
23 +
24 +cpu_apps_create() {
25 +
26 + echo "CHART apps.cpu '' 'Apps CPU' 'milliseconds/s' apps apps stacked 20001 $update_every"
27 +
28 + local x=
29 + for x in $cpu_apps_apps
30 + do
31 + echo "DIMENSION $x $x incremental 1000 $cpu_apps_clockticks"
32 +
33 + # this string is needed later in the update() function
34 + # to finalize the instructions for the bc command
35 + cpu_apps_bc_finalze="$cpu_apps_bc_finalze \"SET $x = \"; $x;"
36 + done
37 + return 0
38 +}
39 +
40 +cpu_apps_update() {
41 + # do all the work to collect / calculate the values
42 + # for each dimension
43 + # remember: KEEP IT SIMPLE AND SHORT
44 +
45 + echo "BEGIN apps.cpu"
46 + ps -o pid,comm -C "$cpu_apps_apps" |\
47 + grep -v "COMMAND" |\
48 + (
49 + while read pid name
50 + do
51 + echo "$name+=`cat /proc/$pid/stat | cut -d ' ' -f 14-15`"
52 + done
53 + ) |\
54 + ( sed -e "s/ \+/ /g" -e "s/ /+/g";
55 + echo "$cpu_apps_bc_finalze"
56 + ) | bc
57 + echo "END"
58 +
59 + return 0
60 +}
plugins.d/charts.d.plugin
+11 -2
@@ -25,6 +25,13 @@ do
25 continue
26 fi
27
28 + if [ "$1" = "debug" -o "$1" = "all" ]
29 + then
30 + debug=1
31 + shift
32 + continue
33 + fi
34 +
35 if [ -f "$chartsd/$1.chart.sh" ]
36 then
37 debug=1
@@ -206,11 +213,13 @@ done
213 # -----------------------------------------------------------------------------
214 # check overwrites
215
209 -# if we only need a specific chart, remove all the others
216 +# enable work time reporting
217 debug_time=
218 +test $debug -eq 1 && debug_time=tellwork
219 +
220 +# if we only need a specific chart, remove all the others
221 if [ ! -z "$chart_only" ]
222 then
213 - debug_time=tellwork
223 check_charts=
224 for x in $active_charts
225 do