]> arthur.barton.de Git - netdata.git/blobdiff - charts.d/postfix.chart.sh
rename chart fields to avoid conflicts with backends; fixes #1962
[netdata.git] / charts.d / postfix.chart.sh
old mode 100755 (executable)
new mode 100644 (file)
index 0a246da..85604fc
@@ -1,4 +1,10 @@
-#!/bin/sh
+# no need for shebang - this file is loaded from charts.d.plugin
+
+# netdata
+# real-time performance and health monitoring, done right!
+# (C) 2016 Costa Tsaousis <costa@tsaousis.gr>
+# GPL v3+
+#
 
 # the postqueue command
 # if empty, it will use the one found in the system path
@@ -7,6 +13,8 @@ postfix_postqueue=
 # how frequently to collect queue size
 postfix_update_every=15
 
+postfix_priority=60000
+
 postfix_check() {
        # this should return:
        #  - 0 to enable the chart
@@ -15,24 +23,12 @@ postfix_check() {
        # try to find the postqueue executable
        if [ -z "$postfix_postqueue" -o ! -x "$postfix_postqueue" ]
        then
-               postfix_postqueue="`which postqueue 2>/dev/null`"
-               if [ -z "$postfix_postqueue" -o ! -x "$postfix_postqueue" ]
-               then
-                       local d=
-                       for d in /sbin /usr/sbin /usr/local/sbin
-                       do
-                               if [ -x "$d/postqueue" ]
-                               then
-                                       postfix_postqueue="$d/postqueue"
-                                       break
-                               fi
-                       done
-               fi
+               postfix_postqueue="$(which postqueue 2>/dev/null || command -v postqueue 2>/dev/null)"
        fi
 
        if [ -z "$postfix_postqueue" -o ! -x  "$postfix_postqueue" ]
        then
-               echo >&2 "$PROGRAM_NAME: postfix: cannot find postqueue. Please set 'postfix_postqueue=/path/to/postqueue' in $confd/postfix.conf"
+               error "cannot find postqueue. Please set 'postfix_postqueue=/path/to/postqueue' in $confd/postfix.conf"
                return 1
        fi
 
@@ -41,9 +37,9 @@ postfix_check() {
 
 postfix_create() {
 cat <<EOF
-CHART postfix.qemails '' "Postfix Queue Emails" "emails" postfix postfix line 5000 $postfix_update_every
+CHART postfix_local.qemails '' "Postfix Queue Emails" "emails" queue postfix.queued.emails line $((postfix_priority + 1)) $postfix_update_every
 DIMENSION emails '' absolute 1 1
-CHART postfix.qsize '' "Postfix Queue Emails Size" "emails size in KB" postfix postfix area 5001 $postfix_update_every
+CHART postfix_local.qsize '' "Postfix Queue Emails Size" "emails size in KB" queue postfix.queued.size area $((postfix_priority + 2)) $postfix_update_every
 DIMENSION size '' absolute 1 1
 EOF
 
@@ -68,17 +64,20 @@ postfix_update() {
        # be very carefull with eval:
        # prepare the script and always egrep at the end the lines that are usefull, so that
        # even if something goes wrong, no other code can be executed
-       eval "`$postfix_postqueue -p |\
+       postfix_q_emails=0
+       postfix_q_size=0
+
+       eval "$(run $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" |\
-               egrep "^local postfix_q_(emails|size)=[0-9]+$"`"
+               egrep "^local postfix_q_(emails|size)=[0-9]+$")"
 
        # write the result of the work.
        cat <<VALUESEOF
-BEGIN postfix.qemails $1
+BEGIN postfix_local.qemails $1
 SET emails = $postfix_q_emails
 END
-BEGIN postfix.qsize $1
+BEGIN postfix_local.qsize $1
 SET size = $postfix_q_size
 END
 VALUESEOF