]> arthur.barton.de Git - netdata.git/blob - charts.d/postfix.chart.sh
postqueue charts
[netdata.git] / charts.d / postfix.chart.sh
1 #!/bin/sh
2
3 postfix_postqueue=
4
5 postfix_check() {
6         # this should return:
7         #  - 0 to enable the chart
8         #  - 1 to disable the chart
9
10         # try to find the postqueue executable
11         if [ -z "$postfix_postqueue" -o ! -x "$postfix_postqueue" ]
12         then
13                 postfix_postqueue="`which postqueue 2>/dev/null`"
14                 if [ -z "$postfix_postqueue" -o ! -x "$postfix_postqueue" ]
15                 then
16                         local d=
17                         for d in /sbin /usr/sbin /usr/local/sbin
18                         do
19                                 if [ -x "$d/postqueue" ]
20                                 then
21                                         postfix_postqueue="$d/postqueue"
22                                         break
23                                 fi
24                         done
25                 fi
26         fi
27
28         if [ -z "$postfix_postqueue" -o ! -x  "$postfix_postqueue" ]
29         then
30                 echo >&2 "Cannot find postqueue. Please set 'postfix_postqueue=/path/to/postqueue' in $confd/postfix.conf"
31                 return 1
32         fi
33
34         return 0
35 }
36
37 postfix_create() {
38 cat <<EOF
39 CHART postfix.qemails '' "Postfix Queue Emails" "emails" postfix postfix line 5000 $update_every
40 DIMENSION emails '' absolute-no-interpolation 1 1
41 CHART postfix.qsize '' "Postfix Queue Emails Size" "emails size in KB" postfix postfix area 5001 $update_every
42 DIMENSION size '' absolute 1 1
43 EOF
44
45         return 0
46 }
47
48 postfix_update() {
49         # do all the work to collect / calculate the values
50         # for each dimension
51         # remember: KEEP IT SIMPLE AND SHORT
52
53         eval `$postfix_postqueue -p | grep "^--" | sed -e "s/-- \([0-9]\+\) Kbytes in \([0-9]\+\) Requests.$/local postfix_q_size=\1\nlocal postfix_q_emails=\2/g" | grep "^local postfix_q_"`
54         test -z "$postfix_q_emails" && local postfix_q_emails=0
55         test -z "$postfix_q_size" && local postfix_q_size=0
56
57         # write the result of the work.
58         cat <<VALUESEOF
59 BEGIN postfix.qemails $1
60 SET emails = $postfix_q_emails
61 END
62 BEGIN postfix.qsize $1
63 SET size = $postfix_q_size
64 END
65 VALUESEOF
66
67         return 0
68 }