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