Posts Tagged ‘Installing qmailanalog and Generating daily qmail statistics with (qmail-stats.py) on Debian Lenny / Daily qmail statististics notification via email’

Installing qmailanalog and Generating daily qmail statistics with (qmail-stats.py) on Debian Lenny / Daily qmail statististics notification via email

Tuesday, April 20th, 2010

Finding a decent software to generate daily qmail statistics is a really tough job this days. Before time I always used eitherqmailalizer or isoqlog.
Presently qmailalizer is completely abondoned piece of software and I cannot force it to work on 64 bit architecture.Isoqlog is another story, it’s supposed to work with qmailrocks, however my qmail installation is based on Bill’s Linux Qmail Toaster and for some strange reason it’s generating empty statistics. It could be that isoqlog is not generating statistics because the log files’s feed to be processed is not enough. Anyways still I cannot figure out the reason why I cannot make work Isoqlog with the Qmail Toaster.

I needed a way to however at least have an overview statistics of what is happening inside qmail. Of course qmailmrtg which is explained how to be installed in my previous post is providing with some overall information, though the information acquired through it is too general.
I’ve spend some enormous time searching for something that could inform me on various qmail statistics based on the qmail logs, before I could find and tweak the qmail-stats.py report script to become usable with qmailanalog

In the meantime It was necessery for me to investigate into qmailanalog and install it on the Debian system.
Initially I instlaled the qmailanalog from source, latest current source release can be obtained via D.J. Bernstein’s qmaialanlog download page
You won’t be able to compile the qmailanalog piece of code in debian until substitute in the source file: error.h the line:

extern int errno;

with#include <errno.h>

After the above change your source should succesfully compile.
Right after I compile it I realized there is a debian source package installer called:
qmailanalog-installer

So on Debian to install qmailanalog all I had to do was:

debian-server:~# apt-get install qmailanalog-installer
debian-server:~# /usr/bin/build-qmailanalog

Now as I already have qmailanalog properly installed on Debian I decided to test it with a script called qmail-logs.sh
You can download the qmail-logs.sh script from here

Here I quote what exactly is written in the qmail-logs.sh header in order to provide you with a general idea what the script does.

## Purpose:
## Wrapper for qmailanalog scripts. Will analyze qmail multilog
## files for deferrals, failures, overall statistics, or convert
## them to sendmail-style logs.

After executing the script I realized the script is not working properly because of some errors issued by scripts included within the qmailanalog package.
The faced problems and their solution with the qmailanalog: zsenders, zsuccesses, zfailures, zrecipients, zfailures and zrhosts scripts I’ve reported as a Debian bugs The qmailanalog bug report I’ve submitted can be seen here

The whole problem with qmailanalog scripts on Debian is that the “gnu more” binary arguments passed during the script operations are not correct and needs to be fixed.
Similar issues and their solution is explained in Qmailrocks Forums threads

After fixing the issues with qmailanalog I tried once again the qmail-logs.sh script, this time some of the functions provided by the script prooved working however some of them weren’t okay still.
Therefore I took some more time searching on the internet and I’ve found on a mailing list the qmail-stats.py script which worked like a charm with a minor modifications.

In order to have the qmail-stats.py working you need the tai64nfrac binary.You can download the latest current version of tai64nfrac on tai64nfrac’s website
Installation of tai64nfrac is pretty straight forward and comes to the following:

debian-server:~# wget http://archives.eyrie.org/software/system/tai64nfrac-1.4.tar.gz
debian-server:~# tar -zxvf tai64nfrac-1.4.tar.gz
debian-server:~# cd tai64nfrac-1.4
debian-server:~# make
debian-esrver:~# make install

After the install you should have the tai64nfrac in /usr/local/bin/tai64nfrac
Now let’s go back to the qmail-stats.py script. I’ve mirrored the qmail-stats.py script the qmail-stats.py script can be downloaded here

The script reports statistics on Qmail Logs following criterias:

Overall Email Server Statistics
Failure Statistics (Reasons for Failure)
Deferrals Statistics (Reasons for Deferrals)
Top Ten Senders Statistics
Top Ten Recipients Statistics

To make the script working all you have to edit in the script is the LOGFILE_PATH the rest is preconfigured by me already in the version of qmail-stats.py which is provided for download above.
If you choose to compile the qmailanalog from source you might also need to change the CMDS options, which includes the directory locations and commands from qmailanalog.

Now if you want to have the reports generated from qmail-stats.py, you have to setup the qmail-stats.py to be running via the cron daemon.

To do so open your root crontab and put in it:

# report daily qmail statistics05 01 * * * /usr/local/bin/qmail-stats.py | mail -s "Qmail Daily Statistics for $(date)" admin@domain.com

Now you should have the qmail-stats.py mailed to you every day at 01:05 early in the morning! 🙂