Monitoring Postfix Queue


This is a very basic postfix queue monitoring script to alert the administrator if the queue is filling up for some reasons.

Understanding the script

We are using the mailq command to see how many messages are about to be sent. The output of mailq should look like this.


$ mailq

-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------

24A12120A80* 479 Tue Apr 29 13:29:16

2669E120A65* 479 Tue Apr 29 13:29:16

28E74120844* 479 Tue Apr 29 13:29:16

-- 2 Kbytes in 3 Requests.

Just see the last line of the output '-- 2 Kbytes in 3 Requests.' 3 request is the key so that we will know how many messages are pending in the queue.

You can extract the the number of requests with the following command:

/usr/bin/mailq | /usr/bin/tail -n1 | /usr/bin/awk '{print }'

Do some queue count validation of your choice before alerting and adjust the limit variable as necessary.

Check the code in github - PostfixQueueMonitoring


About Mboy 26 Articles
I'm a lover and a good friend.. :)