How to monitor Postfix queue length using an SNMP monitor


It’s essential to monitor email queues if you’re an Internet service provider or email service provider. Any of your 1000s of email users might have chosen an insecure password meaning that a script kiddy might come and hack their email box, and in the process unleash 1000s of messages of even 100 000s of messages meaning your email server will be blacklisted. Although it’s recoverable, the quicker you find the problem, the easier it will be to solve. If you leave the problem for more than a few days, you might end up spending days, weeks, and sometimes even months fixing the problem. The fact of the matter is once you have been banned by a couple of high profile spam detection services, delisting is not a joke.

Queue monitoring using Postfix and PRTG

Postfix is a really popular MTA and often used to send emails. This article covers a method for monitoring the Postfix queue. There are other methods as well, but this method is really straightforward and works if you have also have PRTG installed. The article is the work of a forum contributor at PRTG with small modifications.

The Script

cat /etc/postfix/

# 20.06.2011 - JJaritsch @ ANEXIA Internetdienstleistungs GmbH
# jj @

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

Change owner, assign correct permissions, and make executable:

chown postfix:postfix
chmod 755
chmod +x

Add to /etc/snmp/snmpd.conf


exec postqueue /usr/bin/sudo /etc/postfix/

Add to /etc/sudoers

snmp ALL=(ALL) NOPASSWD: /etc/postfix/

Restart service

service snmpd restart

In PRTG / Add Sensor / SNMP Custom


To test from the command line:

snmpwalk -c your_community -v 2c localhost


Share this article

Leave a Reply

Your email address will not be published.

Scroll to Top