]> arthur.barton.de Git - netdata.git/blob - charts.d/cpu_apps.chart.sh
Merge pull request #523 from paulfantom/master
[netdata.git] / charts.d / cpu_apps.chart.sh
1 #!/bin/sh
2
3 # THIS PLUGIN IS OBSOLETE
4 # USE apps.plugin INSTEAD
5
6 # a space separated list of command to monitor
7 cpu_apps_apps=
8
9 # these are required for computing memory in bytes and cpu in seconds
10 #cpu_apps_pagesize="`getconf PAGESIZE`"
11 cpu_apps_clockticks="$(getconf CLK_TCK)"
12
13 cpu_apps_update_every=60
14
15 cpu_apps_check() {
16         # this should return:
17         #  - 0 to enable the chart
18         #  - 1 to disable the chart
19
20         if [ -z "$cpu_apps_apps" ]
21         then
22                 echo >&2 "$PROGRAM_NAME: cpu_apps: Please set cpu_apps_apps='command1 command2 ...' in $confd/cpu_apps_apps.conf"
23                 return 1
24         fi
25         return 0
26 }
27
28 cpu_apps_bc_finalze=
29
30 cpu_apps_create() {
31
32         echo "CHART chartsd_apps.cpu '' 'Apps CPU' 'milliseconds / $cpu_apps_update_every sec' apps apps stacked 20001 $cpu_apps_update_every"
33
34         local x=
35         for x in $cpu_apps_apps
36         do
37                 echo "DIMENSION $x $x incremental 1000 $cpu_apps_clockticks"
38
39                 # this string is needed later in the update() function
40                 # to finalize the instructions for the bc command
41                 cpu_apps_bc_finalze="$cpu_apps_bc_finalze \"SET $x = \"; $x;"
42         done
43         return 0
44 }
45
46 cpu_apps_update() {
47         # do all the work to collect / calculate the values
48         # for each dimension
49         # remember: KEEP IT SIMPLE AND SHORT
50
51         echo "BEGIN chartsd_apps.cpu"
52         ps -o pid,comm -C "$cpu_apps_apps" |\
53                 grep -v "COMMAND" |\
54                 (
55                         while read pid name
56                         do
57                                 echo "$name+=`cat /proc/$pid/stat | cut -d ' ' -f 14-15`"
58                         done
59                 ) |\
60                 (       sed -e "s/ \+/ /g" -e "s/ /+/g";
61                         echo "$cpu_apps_bc_finalze"
62                 ) | bc
63         echo "END"
64
65         return 0
66 }