How To: Monitoring e-mail queue on postfix with PRTG

Unfortunately Postfix doesn’t store any statistics on its own so all that data must be collected while processed. You can do this via a script triggered by PRTG.

Collecting data from mail queue

You can monitor the queues with a simple bashscript:

# 20.06.2011 - JJaritsch @ ANEXIA Internetdienstleistungs GmbH

queuelength=$( /usr/sbin/postqueue -p | tail -n1 | awk '{print $5}' )
queuecount=$( echo $queuelength | grep "[0-9]" )

if [ "$queuecount" == "" ]; then
        echo 0;
        echo ${queuelength};
exit 35

Save this script and make it executable (0755 is enough) for the snmpd user. The next step is to add the following line to your snmpd.conf:

exec postqueue /path/to/your/

If you want to use sudo, you can add this line:

exec postqueue /usr/bin/sudo /path/to/your/

In case of sudo you also have to add the following to your sudoers file (so there is no auth required to execute this script):

snmp ALL=(ALL) NOPASSWD: /path/to/your/

Reload your snmpd - you will find the count-result in .* (for example in . if you have no other additional lines in the snmpd.conf).