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
ubuntu:

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 mail_stat.pl to <your cacti root>/scripts/ directory.

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

yum install perl-Net-SNMP

ubuntu:

apt-get install libnet-snmp-perl

Congratulations! you’ve done.

Notes:
1. In order for the mail_stat.pl 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 mail_stat.pl
for example, you may find out the OID this way:

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

output:

.1.3.6.1.4.1.2021.8.1.1.1 = INTEGER: 1
.1.3.6.1.4.1.2021.8.1.2.1 = STRING: mailstat
.1.3.6.1.4.1.2021.8.1.3.1 = STRING: /bin/cat /var/tmp/mailstat
.1.3.6.1.4.1.2021.8.1.100.1 = INTEGER: 0
.1.3.6.1.4.1.2021.8.1.101.1 = STRING: sent:1 received:0 bounced:0 rejected:0 virus:0 spam:0
.1.3.6.1.4.1.2021.8.1.102.1 = INTEGER: noError(0)
.1.3.6.1.4.1.2021.8.1.103.1 = STRING:

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

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

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

yum install perl-Crypt-Rijndael

ubuntu:

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

    email: danilorpneves@gmail.com

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

Leave a Reply