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