Awstats is a commonly used program to calculate web statistics from your webserver logfiles. It can detect useragents, referers, unique visitors… But one of its another feature is to build usage reports from your mail server’s logfiles, as seen on this demo.
Here is how to quickly configure Awstats to take profit of your Qmail log files…
First of all, you need to convert rour /var/log/mail.log file to make it readable to Awstats (supposing you’re using Qmail and Vpopmail from Dotdeb and Awstats from Debian’s official repositories).
Hopefully, a tool is provided with the awstats package : /usr/share/doc/awstats/examples/maillogconvert.pl
You can take a look at its output by executing the following command :
/usr/share/doc/awstats/examples/maillogconvert.pl vadmin /var/log/mail.log |
(vadmin is here to consider the Vpopmail’s virtualdomain translation)
Great! We now just have to configure awstats to produce useful reports. Here is a sample configuration file (name it /etc/awstats/awstats.mail.conf, for example)… Please note the space after the pipe :
LogFile="/usr/share/doc/awstats/examples/maillogconvert.pl vadmin /var/log/mail.log | " LogType=M LogFormat="%time2 %email %email_r %host %host_r %method %url %code %bytesd" SiteDomain="localhost" HostAliases="127.0.0.1 @/etc/qmail/rcpthosts" LevelForBrowsersDetection=0 # 0 disables Browsers detection. LevelForOSDetection=0 # 0 disables OS detection. LevelForRefererAnalyze=0 # 0 disables Origin detection. LevelForRobotsDetection=0 # 0 disables Robots detection. LevelForSearchEnginesDetection=0 # 0 disables Search engines detection. LevelForKeywordsDetection=0 # 0 disables Keyphrases/Keywords detection. LevelForFileTypesDetection=0 # 0 disables File types detection. ShowSummary=HB ShowMonthStats=HB ShowDaysOfMonthStats=HB ShowDaysOfWeekStats=HB ShowHoursStats=HB ShowDomainsStats=0 ShowHostsStats=HBL ShowRobotsStats=0 ShowEMailSenders=HBML ShowEMailReceivers=HBML ShowSessionsStats=0 ShowPagesStats=0 ShowFileTypesStats=0 ShowOSStats=0 ShowBrowsersStats=0 ShowOriginStats=0 ShowKeyphrasesStats=0 ShowKeywordsStats=0 ShowMiscStats=0 ShowHTTPErrorsStats=0 ShowSMTPErrorsStats=1 |
Now, just add this line to /etc/cron.d/awstats to compute your logfiles every 10 minutes:
0,10,20,30,40,50 * * * * root [ -x /usr/lib/cgi-bin/awstats.pl ] && /usr/lib/cgi-bin/awstats.pl -config=mail -update &>/dev/null
(Let’s enjoy a 10-minutes break or brew a good coffee, waiting for the stats to be calculated…)
Your mailserver’s statistics will shortly be available at this URL : http://yourserver/cgi-bin/awstats.pl?config=mail.
3 replies on “Calculate statistics from your Qmail logfiles using Awstats”
Sounds great !
Can’t wait to test it.
Thanks for the tip 😉
[…] and Report from your qmail logfiles is awstast, I’ve found the following article called Calculate Statistics From your Qmail logfiles an interesting reading and a good learning point.Hope it’s gonna be helpful for you too. […]
That was enjoyable to read, thanks for posting it.