]> arthur.barton.de Git - netdata.git/blob - charts.d/mem_apps.chart.sh
added mem.apps and improved error handling and debugging for charts.d
[netdata.git] / charts.d / mem_apps.chart.sh
1 #!/bin/sh
2
3 mem_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 #mem_apps_pagesize="`getconf PAGESIZE`"
7 #mem_apps_clockticks="`getconf CLK_TCK`"
8
9 mem_apps_check() {
10         # this should return:
11         #  - 0 to enable the chart
12         #  - 1 to disable the chart
13
14         if [ -z "$mem_apps_apps" ]
15         then
16                 echo >&2 "mem_apps: Please set mem_apps_apps='command1 command2 ...' in $confd/mem_apps_apps.conf"
17                 return 1
18         fi
19         return 0
20 }
21
22 mem_apps_bc_finalze=
23
24 mem_apps_create() {
25
26         cat <<EOF1
27 CHART system.apps '' "Apps Memory" "MB" "mem" "mem" stacked 20000 $update_every
28 EOF1
29
30         local x=
31         for x in $mem_apps_apps
32         do
33
34 cat <<EOF1
35 DIMENSION $x $x absolute 1 1024
36 EOF1
37                 # this string is needed later in the update() function
38                 # to finalize the instructions for the bc command
39                 mem_apps_bc_finalze="$mem_apps_bc_finalze \"SET $x = \"; $x;"
40         done
41         return 0
42 }
43
44 mem_apps_egrep="(`echo "$mem_apps_apps" | sed -e "s/^ \+//g" -e "s/ \+$//g" -e "s/ /|/g"`)"
45 mem_apps_update() {
46         # do all the work to collect / calculate the values
47         # for each dimension
48         # remember: KEEP IT SIMPLE AND SHORT
49
50         echo "BEGIN system.apps"
51         ps -e -o comm,rss |\
52                 egrep "^$mem_apps_egrep " |\
53                 (       sed -e "s/ \+/ /g" -e "s/ /+=/g";
54                         echo "$mem_apps_bc_finalze"
55                 ) | bc
56         echo "END"
57
58         return 0
59 }
60