Monitoring email server with Cacti

Inspired by a Cacti forum post, and bothered by the bug/fault the existing solution contains. I decide to write a new tempalte for this task.

This template use mailgraph to gather MTA mail statistics counter, then export them to other host via SNMP. Cacti then poll the statistics info from SNMP, graph it out using rrdtools. All MTA that mailgraph supports should work with this template(sendmail,Postfix included).

Install instructions

On host to be monitored

1. Install mailgraph in your desired way

apt-get install mailgraph

CentOS: add epel repo, then.

yum install mailgraph

2. Patch mailgraph
patch mailgraph with the included mailgraph.patch file.

patch -b /usr/sbin/mailgraph mailgraph.patch

then, restart mailgraph.
after some time(depends on how large your mail log is), a file
will appear at /var/tmp/mailstat

3. Add the following line to your snmpd.conf, make sure that it is the first exec rule
in that file.

#export mail statistics info from mailgraph
exec mailstat /bin/cat /var/tmp/mailstat

then, restart snmpd

On your cacti host

1. Import the graph template xml(…1_minute_average.xml or …5_minute_average.xml) file into cacti.
then you can add the graph to your host using the Mail Statistics – 5 Minute Average
or Mail Statistics – 1 Minute Average graph template.

2. Copy the to <your cacti root>/scripts/ directory.

3. Make sure that you have the Net-SNMP perl module, if not, install them.

yum install perl-Net-SNMP


apt-get install libnet-snmp-perl

Congratulations! you’ve done.

1. In order for the to work, the “exec” directive added to snmpd.conf
should be the first exec directive, if not, you need to find out the correct OID,
then change it in
for example, you may find out the OID this way:

snmpwalk -On -v2c -c community_id localhost ucdavis.extTable


. = INTEGER: 1
. = STRING: mailstat
. = STRING: /bin/cat /var/tmp/mailstat
. = INTEGER: 0
. = STRING: sent:1 received:0 bounced:0 rejected:0 virus:0 spam:0
. = INTEGER: noError(0)

you can see from the output that OID for mailstat is: .
and change the oid in

#oid of the mailstat exec extension in snmp agent
my $mailstat = '.';

2. If you use SHA as the auth protocol for SNMP v3 , you need to install another perl module

yum install perl-Crypt-Rijndael


apt-get install libcrypt-rijndael-perl

Click here to download Cacti graph template for mail server monitoring

This entry was posted in System Administration and tagged , , , . Bookmark the permalink.

2 Responses to Monitoring email server with Cacti

  1. Danilo Neves says:

    very good, I’m Brazilian and I did your example.
    thank you


  2. Pingback: Postfixの監視 | 多脚.com

Leave a Reply