]> arthur.barton.de Git - netdata.git/blob - charts.d/cpu_apps.chart.sh
report per second incremental values when update frequency is higher than a second
[netdata.git] / charts.d / cpu_apps.chart.sh
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_update_every=60
10
11 cpu_apps_check() {
12         # this should return:
13         #  - 0 to enable the chart
14         #  - 1 to disable the chart
15
16         if [ -z "$cpu_apps_apps" ]
17         then
18                 echo >&2 "cpu_apps: Please set cpu_apps_apps='command1 command2 ...' in $confd/cpu_apps_apps.conf"
19                 return 1
20         fi
21         return 0
22 }
23
24 cpu_apps_bc_finalze=
25
26 cpu_apps_create() {
27
28         echo "CHART apps.cpu '' 'Apps CPU' 'milliseconds / $cpu_apps_update_every sec' apps apps stacked 20001 $cpu_apps_update_every"
29
30         local x=
31         for x in $cpu_apps_apps
32         do
33                 echo "DIMENSION $x $x incremental 1000 $((cpu_apps_clockticks * cpu_apps_update_every))"
34
35                 # this string is needed later in the update() function
36                 # to finalize the instructions for the bc command
37                 cpu_apps_bc_finalze="$cpu_apps_bc_finalze \"SET $x = \"; $x;"
38         done
39         return 0
40 }
41
42 cpu_apps_update() {
43         # do all the work to collect / calculate the values
44         # for each dimension
45         # remember: KEEP IT SIMPLE AND SHORT
46
47         echo "BEGIN apps.cpu"
48         ps -o pid,comm -C "$cpu_apps_apps" |\
49                 grep -v "COMMAND" |\
50                 (
51                         while read pid name
52                         do
53                                 echo "$name+=`cat /proc/$pid/stat | cut -d ' ' -f 14-15`"
54                         done
55                 ) |\
56                 (       sed -e "s/ \+/ /g" -e "s/ /+/g";
57                         echo "$cpu_apps_bc_finalze"
58                 ) | bc
59         echo "END"
60
61         return 0
62 }