[Dovecot] Plugin for munin

Micah Anderson micah at riseup.net
Sun Dec 4 21:03:55 EET 2011


Eduardo Casarero <ecasarero at gmail.com> writes:

> 2011/12/2 Patrick Westenberg <pw at wk-serv.de>
>
>> Hi there,
>>
>> is anyone using munin to monitor connections to dovecot?
>> If someone does, which plugin is used?

I'm using the one from nagiosexchange, but I modified it for dovecot2:

#!/bin/sh
#
# Munin Plugin
# to count logins to your dovecot mailserver
# 
# Created by Dominik Schulz <lkml at ds.gauner.org>
# http://developer.gauner.org/munin/
# Contributions by:
# - Stephane Enten <tuf at delyth.net>
# - Micah Anderson <micah at riseup.net> (updated for dovecot2)
# 
# Parameters understood:
#
# config    (required)
# autoconf  (optional - used by munin-config)
# 
# Config variables:
#
#       logfile      - Where to find the syslog file
#
# Add the following line to a file in /etc/munin/plugin-conf.d:
#   env.logfile /var/log/your/logfile.log
#
# Magic markers (optional - used by munin-config and installation scripts):
#
#%# family=auto
#%# capabilities=autoconf

######################
# Configuration
######################
STAT_FILE=/var/lib/munin/plugin-state/plugin-dovecot.state
EXPR_BIN=/usr/bin/expr
LOGFILE=${logfile:-/var/log/mail.log}
######################

if [ "$1" = "autoconf" ]; then
  echo yes
  exit 0
fi

if [ "$1" = "config" ]; then
  echo 'graph_title Dovcecot Logins'
  echo 'graph_args --base 1000 -l 0'
  echo 'graph_vlabel Login Counters'
  echo 'login_total.label Total Logins'
  echo 'login_tls.label TLS Logins'
  echo 'login_ssl.label SSL Logins'
  echo 'login_imap.label IMAP Logins'
  echo 'login_pop3.label POP3 Logins'
  echo 'connected.label Connected Users'
  exit 0
fi

#############################
# Initialization
#############################
if [ ! -r $STAT_FILE ]; then
  echo "TOTAL=0" > $STAT_FILE
  echo "TLS=0" >> $STAT_FILE
  echo "SSL=0" >> $STAT_FILE
  echo "IMAP=0" >> $STAT_FILE
  echo "POP3=0" >> $STAT_FILE
fi
#############################


######################
# Total Logins
######################
/bin/echo -en "login_total.value "
NEW_TOTAL=$(egrep 'dovecot.*Login' $LOGFILE | grep "`date '+%b %e'`" | sort | wc -l)
OLD_TOTAL=$(grep TOTAL $STAT_FILE | cut -f2 -d '=')
TOTAL=$($EXPR_BIN $NEW_TOTAL - $OLD_TOTAL)
if [ $TOTAL -gt 0 ]; then
  echo "$TOTAL"
else
  echo "0"
fi
echo -n
######################
# Connected Users
######################
CONNECTS=$(doveadm -f flow who -1 |wc -l)
/bin/echo -en "connected.value "
echo $CONNECTS
echo -n
######################
# TLS Logins
######################
/bin/echo -en "login_tls.value "
NEW_TLS=$(egrep 'dovecot.*Login.*TLS' $LOGFILE | grep "`date '+%b %e'`" | sort | wc -l)
OLD_TLS=$(grep TLS $STAT_FILE | cut -f2 -d '=')
TLS=$($EXPR_BIN $NEW_TLS - $OLD_TLS)
if [ $TLS -gt 0 ]; then
  echo "$TLS"
else
  echo "0"
fi
echo -n
######################
# SSL Logins
######################
/bin/echo -en "login_ssl.value "
NEW_SSL=$(egrep 'dovecot.*Login.*SSL' $LOGFILE | grep "`date '+%b %e'`" | sort | wc -l)
OLD_SSL=$(grep SSL $STAT_FILE | cut -f2 -d '=')
SSL=$($EXPR_BIN $NEW_SSL - $OLD_SSL)
if [ $SSL -gt 0 ]; then
  echo "$SSL"
else
  echo "0"
fi
echo -n
######################
# IMAP Logins
######################
/bin/echo -en "login_imap.value "
NEW_IMAP=$(egrep 'dovecot.*imap.*Login' $LOGFILE | grep "`date '+%b %e'`" | sort | wc -l)
OLD_IMAP=$(grep IMAP $STAT_FILE | cut -f2 -d '=')
IMAP=$($EXPR_BIN $NEW_IMAP - $OLD_IMAP)
if [ $IMAP -gt 0 ]; then
  echo "$IMAP"
else
  echo "0"
fi
echo -n
######################
# POP3 Logins
######################
/bin/echo -en "login_pop3.value "
NEW_POP3=$(egrep 'dovecot.*pop3.*Login' $LOGFILE | grep "`date '+%b %e'`" | sort | wc -l)
OLD_POP3=$(grep POP3 $STAT_FILE | cut -f2 -d '=')
POP3=$($EXPR_BIN $NEW_POP3 - $OLD_POP3)
if [ $POP3 -gt 0 ]; then
  echo "$POP3"
else
  echo "0"
fi
echo -n
######################
# Save the new values
######################
echo "TOTAL=$NEW_TOTAL" > $STAT_FILE
echo "TLS=$NEW_TLS" >> $STAT_FILE
echo "SSL=$NEW_SSL" >> $STAT_FILE 
echo "IMAP=$NEW_IMAP" >> $STAT_FILE
echo "POP3=$NEW_POP3" >> $STAT_FILE




More information about the dovecot mailing list