1 # no need for shebang - this file is loaded from charts.d.plugin
4 # real-time performance and health monitoring, done right!
5 # (C) 2016 Costa Tsaousis <costa@tsaousis.gr>
9 # the postqueue command
10 # if empty, it will use the one found in the system path
13 # how frequently to collect queue size
14 postfix_update_every=15
16 postfix_priority=60000
20 # - 0 to enable the chart
21 # - 1 to disable the chart
23 # try to find the postqueue executable
24 if [ -z "$postfix_postqueue" -o ! -x "$postfix_postqueue" ]
26 postfix_postqueue="$(which postqueue 2>/dev/null || command -v postqueue 2>/dev/null)"
29 if [ -z "$postfix_postqueue" -o ! -x "$postfix_postqueue" ]
31 error "cannot find postqueue. Please set 'postfix_postqueue=/path/to/postqueue' in $confd/postfix.conf"
40 CHART postfix_local.qemails '' "Postfix Queue Emails" "emails" queue postfix.queued.emails line $((postfix_priority + 1)) $postfix_update_every
41 DIMENSION emails '' absolute 1 1
42 CHART postfix_local.qsize '' "Postfix Queue Emails Size" "emails size in KB" queue postfix.queued.size area $((postfix_priority + 2)) $postfix_update_every
43 DIMENSION size '' absolute 1 1
50 # the first argument to this function is the microseconds since last update
51 # pass this parameter to the BEGIN statement (see bellow).
53 # do all the work to collect / calculate the values
55 # remember: KEEP IT SIMPLE AND SHORT
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
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
70 eval "$(run $postfix_postqueue -p |\
72 sed -e "s/-- \([0-9]\+\) Kbytes in \([0-9]\+\) Requests.$/local postfix_q_size=\1\nlocal postfix_q_emails=\2/g" |\
73 egrep "^local postfix_q_(emails|size)=[0-9]+$")"
75 # write the result of the work.
77 BEGIN postfix_local.qemails $1
78 SET emails = $postfix_q_emails
80 BEGIN postfix_local.qsize $1
81 SET size = $postfix_q_size