]> arthur.barton.de Git - netdata.git/blob - charts.d/postfix.chart.sh
normalized all charts.d plugins
[netdata.git] / charts.d / postfix.chart.sh
1 #!/bin/sh
2
3 # the postqueue command
4 # if empty, it will use the one found in the system path
5 postfix_postqueue=
6
7 # how frequently to collect queue size
8 postfix_update_every=15
9
10 postfix_check() {
11         # this should return:
12         #  - 0 to enable the chart
13         #  - 1 to disable the chart
14
15         # try to find the postqueue executable
16         if [ -z "$postfix_postqueue" -o ! -x "$postfix_postqueue" ]
17         then
18                 postfix_postqueue="`which postqueue 2>/dev/null`"
19                 if [ -z "$postfix_postqueue" -o ! -x "$postfix_postqueue" ]
20                 then
21                         local d=
22                         for d in /sbin /usr/sbin /usr/local/sbin
23                         do
24                                 if [ -x "$d/postqueue" ]
25                                 then
26                                         postfix_postqueue="$d/postqueue"
27                                         break
28                                 fi
29                         done
30                 fi
31         fi
32
33         if [ -z "$postfix_postqueue" -o ! -x  "$postfix_postqueue" ]
34         then
35                 echo >&2 "$PROGRAM_NAME: postfix: cannot find postqueue. Please set 'postfix_postqueue=/path/to/postqueue' in $confd/postfix.conf"
36                 return 1
37         fi
38
39         return 0
40 }
41
42 postfix_create() {
43 cat <<EOF
44 CHART postfix.qemails '' "Postfix Queue Emails" "emails" postfix postfix line 5000 $postfix_update_every
45 DIMENSION emails '' absolute 1 1
46 CHART postfix.qsize '' "Postfix Queue Emails Size" "emails size in KB" postfix postfix area 5001 $postfix_update_every
47 DIMENSION size '' absolute 1 1
48 EOF
49
50         return 0
51 }
52
53 postfix_update() {
54         # the first argument to this function is the microseconds since last update
55         # pass this parameter to the BEGIN statement (see bellow).
56
57         # do all the work to collect / calculate the values
58         # for each dimension
59         # remember: KEEP IT SIMPLE AND SHORT
60
61         # 1. execute postqueue -p
62         # 2. get the line that begins with --
63         # 3. match the 2 numbers on the line and output 2 lines like these:
64         #    local postfix_q_size=NUMBER
65         #    local postfix_q_emails=NUMBER
66         # 4. then execute this a script with the eval
67         #
68         # be very carefull with eval:
69         # prepare the script and always egrep at the end the lines that are usefull, so that
70         # even if something goes wrong, no other code can be executed
71         eval "`$postfix_postqueue -p |\
72                 grep "^--" |\
73                 sed -e "s/-- \([0-9]\+\) Kbytes in \([0-9]\+\) Requests.$/local postfix_q_size=\1\nlocal postfix_q_emails=\2/g" |\
74                 egrep "^local postfix_q_(emails|size)=[0-9]+$"`"
75
76         # write the result of the work.
77         cat <<VALUESEOF
78 BEGIN postfix.qemails $1
79 SET emails = $postfix_q_emails
80 END
81 BEGIN postfix.qsize $1
82 SET size = $postfix_q_size
83 END
84 VALUESEOF
85
86         return 0
87 }