summaryrefslogtreecommitdiffstats
path: root/roles/common/files/usr/local/share/munin/plugins/postfix_mailvolume2
diff options
context:
space:
mode:
Diffstat (limited to 'roles/common/files/usr/local/share/munin/plugins/postfix_mailvolume2')
-rwxr-xr-xroles/common/files/usr/local/share/munin/plugins/postfix_mailvolume262
1 files changed, 62 insertions, 0 deletions
diff --git a/roles/common/files/usr/local/share/munin/plugins/postfix_mailvolume2 b/roles/common/files/usr/local/share/munin/plugins/postfix_mailvolume2
new file mode 100755
index 0000000..d16d88e
--- /dev/null
+++ b/roles/common/files/usr/local/share/munin/plugins/postfix_mailvolume2
@@ -0,0 +1,62 @@
+#!/bin/sh
+
+# Munin plugin for monitoring Postfix per-instance mail throughput.
+# Copyright © 2015 Guilhem Moulin <guilhem@fripost.org>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+PATH=/usr/bin:/bin:/usr/sbin:/sbin
+set -u
+
+LOGFILE="/var/log/${logfile:-mail.log}"
+STATEFILE="$MUNIN_PLUGSTATE/${0##*/}.offset"
+
+case "${1:-}" in
+ config) cat <<- EOF
+ graph_title Postfix per-instance bytes throughput
+ graph_vlabel bytes per \${graph_period}
+ graph_args --base 1024 -l 0
+ graph_scale yes
+ graph_period minute
+ graph_category postfix
+ EOF
+ if [ $(echo "${postmulti:-postfix}" | wc -w) -gt 1 ]; then
+ echo graph_total total throughput
+ fi
+ for postfix in ${postmulti:-postfix}; do
+ echo "${postfix}_volume.label" "$postfix throughput"
+ echo "${postfix}_volume.type" DERIVE
+ echo "${postfix}_volume.min" 0
+ done
+ exit 0
+ ;;
+esac
+
+if [ ! -f "$LOGFILE" ]; then
+ for postfix in ${postmulti:-postfix}; do
+ echo "${postfix}_volume.value U"
+ done
+ exit 0;
+fi
+
+tmpfile="$(mktemp --tmpdir)"
+trap 'rm -f "$tmpfile"' EXIT
+
+logtail -f"$LOGFILE" -o"$STATEFILE" >"$tmpfile"
+
+for postfix in ${postmulti:-postfix}; do
+ echo -n "${postfix}_volume.value "
+ sed -nr "s#^\w{3} [ :[:digit:]]{11} [._[:alnum:]-]+ $postfix/qmgr\[[[:digit:]]+\]: [[:xdigit:]]+: from=<[^>]*>, size=([[:digit:]]+), nrcpt=[[:digit:]]+ \(queue active\)\$#\1#p" "$tmpfile" \
+ | awk 'BEGIN{x=0} {x+=$0} END{print x}'
+done