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).
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 mail_stat.pl 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 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
.126.96.36.199.4.1.2021.8.1.1.1 = INTEGER: 1 .188.8.131.52.4.1.2021.8.1.2.1 = STRING: mailstat .184.108.40.206.4.1.2021.8.1.3.1 = STRING: /bin/cat /var/tmp/mailstat .220.127.116.11.4.1.2021.8.1.100.1 = INTEGER: 0 .18.104.22.168.4.1.2021.8.1.101.1 = STRING: sent:1 received:0 bounced:0 rejected:0 virus:0 spam:0 .22.214.171.124.4.1.2021.8.1.102.1 = INTEGER: noError(0) .126.96.36.199.4.1.2021.8.1.103.1 = STRING:
you can see from the output that OID for mailstat is: .188.8.131.52.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 = '.184.108.40.206.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
yum install perl-Crypt-Rijndael
apt-get install libcrypt-rijndael-perl
Click here to download Cacti graph template for mail server monitoring