By Charly Kühnast
Mailgraph has been giving me useful information for a long while now [1]. It is time to turn the spotlight on this visualization tool for Postfix logfiles and to introduce the related Queuegraph project. Mailgraph [2] is a small footprint daemon that continuously reads the Postfix logfile and shovels the data it gathers into a round robin database (RRD). The front-end is a CGI script that generates a graph based on the RRD data.
The program requires the ubiquitous Perl interpreter, RRDTool [3] for the database, and the File::Tail Perl module, which you can obtain from the CPAN archive. The heart of Mailgraph is a Perl script called mailgraph.pl; the daemon I referred to earlier. You can launch the daemon manually, but it makes more sense to add the init script provided by the distribution to run the daemon when you boot your machine. I use the following command to launch Mailgraph:
mailgraph --daemon --logfile /var/log/postfix --ignore-localhost
The --ignore-localhost parameter prevents mail traffic from or to 127.0.0.1 from being collected, as this traffic mainly has to do with connections to the virus or spam filters running on the same machine.
I use mailgraph.cgi to display the results. I might need to modify the paths to the RRDs (one for mail traffic and another for bounce, virus, and spam information) in the script. Mailgraph also needs a temporary directory, which must be writeable by the web server. On my machine, I set this up with:
my $rrd = '/var/log/mailgraph.rrd'; my $rrd_virus = '/var/log/mailgraph_virus.rrd'; my $tmp_dir = '/tmp/mailgraph';
That's all. After allowing Mailgraph to collect data for a while, I can call http://web-server-URL/cgi-bin/mailgraph.cgi to view the results (see Figure 1).
Queuegraph, a tool that very much resembles Mailgraph, outputs mail queue statistics [4]. In contrast to Mailgraph, Queuegraph does not automatically create the RRD when first launched. You need to run a shell script called createrrd.sh to do this. Don't forget to modify the path for the RRD in the script; the path will default to /etc/postfix otherwise. Queuegraph is not a daemon; instead it is launched once a minute by cron:
* * * * * /usr/local/bin/count.sh &
In count.sh, you simply need to modify the path to the RRD, unless you accept the default. You can drop the two CGI scripts into the CGI directory on your web server alongside mailgraph.cgi.
INFO |
[1] G. Greve, Brave GNU World, Linux Magazine, issue #53 / April, p94
[2] Mailgraph: http://people.ee.ethz.ch/~dws/software/mailgraph/ [3] RRDTool: http://people.ee.ethz.ch/~oetiker/webtools/rrdtool/ [4] Queuegraph: http://www.stahl.bau.tu-bs.de/~hildeb/postfix/queuegraph/ |
THE AUTHOR |
Charly Kühnast is a Unix System Manager at the data-center in Moers, near Germany's famous River Rhine. His tasks include ensuring firewall security and availability and taking care of the DMZ (demilitarized zone). |