Postfix Monitoring With Mailgraph And pflogsumm

por | 26 octubre, 2018



To install pflogsumm, we run

aptitude install pflogsumm

We want pflogsumm to be run by a cron job each day and send the report to Therefore we must configure our system that it writes one mail log file for 24 hours, and afterwards starts the next mail log so that we can feed the old mail log to pflogsumm. Therefore we configure logrotate (that’s the program that rotates our system’s log files) like this: open /etc/logrotate.conf and append the following stanza to it, after the line # system-specific logs may be configured here:

vi /etc/logrotate.conf

# system-specific logs may be configured here
/var/log/mail.log {
    rotate 7
    start 0

There’s a logrotate script in /etc/cron.daily. This script is called every day between 06:00h and 07:00h. With the configuration we just made, it will copy the current Postfix log /var/log/mail.log to /var/log/mail.log.0 and compress it, and the compressed file will be /var/log/mail.log.0.gz. It will also create a new, empty /var/log/mail.log to which Postfix can log for the next 24 hours.

Now we create the script /usr/local/sbin/ which invokes pflogsumm and makes it send the report to

vi /usr/local/sbin/

gunzip /var/log/mail.log.0.gz

pflogsumm /var/log/mail.log.0 | formail -c -I"Subject: Mail Statistics" -I"From: pflogsumm@localhost" -I"To:" -I"Received: from ([])" | sendmail

gzip /var/log/mail.log.0
exit 0

We must make this script executable:

chmod 755 /usr/local/sbin/

Then we create a cron job which calls the script everyday at 07:00h:

crontab -e

0 7 * * * /usr/local/sbin/ &> /dev/null

This will send the report to It looks like this in an email client: