^TipsAnd...

?TableOfContents

To analize the qmail log files and generate statistical information one can use the qmailanalog package from the author of qmail, Dan Bernstein, see: http://cr.yp.to/qmailanalog.html for the original package.

We have a patched version with the following features:

  • can analize multilog generated logs (tai64 timestamps)
  • works with GNU sort (-k_n_ instead of +n)
  • provides mlmatchup for direct use of multilog ! procesor
  • added clean target to Makefile We also have a simple shell script: qareport to postprocess the created output.

Get it from http://www.magma.com.ni/trac/browser/qmailanalog

Note! This is only useful, if you use multilog from the daemontools package or svlogd, the GPLed multilog replacement from Gerrit Pape.

Compilation and Installation

  1. Get and unpack qmailanalog-0.70
  2. Get qmailanalog-multilog.patch.gz
  3. apply the patch
  4. make
  5. as root: make setup check

Prepare the qmail-send log service

For this explanation we suppose that qmail-send is set up as a supervised service in the directory /etc/qmail/qmail-send and that qmailanalog is installed in /usr/local/qmailanalog.

A typical log service for qmail-send in the subdirectory /etc/qmail/qmail-send/log would look like this:

#!/bin/sh

exec setuidgid qmaill multilog t ./main

We want to save the processed logs in the subdirectory qmailanalog and make it accessible to the adm group:

cd /etc/qmail/qmail-send/log
mkdir qmailanalog
chown qmaill:adm qmailanalog
chmod 2750 qmailanalog

Then we extend the last line of the log service to read:

exec setuidgid qmaill multilog t ./main \
  !/usr/local/qmailanalog/bin/mlmatchup ./qmailanalog

Now we are ready to restart the log service, as root:

svc -t .

Periodically create (qa)reports

To get daily, monthly and yearly summaries generated automatically use the files in the qareports subdirectory. You need to adapt the qareports script. Edit the lines with: MATCHUPDIR, REPORTDIR and QABIN to match your requirements. Following the above example you only need to set REPORTDIR to any directory you want the reports beeing generated in.

qareports finds all saved logfiles from one day ago, concatenates them into the file raw.data in a directory named 'REPORTDIR/YYYY/MM/DD' and generates (almost) all z* reports from the qmailanalog packages out of them. It also updates raw.data in 'REPORTDIR/YYYY/MM' and 'REPORTDIR/YYYY' and generates the same reports in these directories.

For REPORTDIR you can use a directory readable by your webbrowser, which allows you to browse and read the reports online. In this case you might want to protect the reports with a password or other access control method.

As root:

  1. Copy the script qareports to /usr/local/qmailanalog/bin
  2. Install qmaill.crontab as crontab for the qmaill user:
    crontab -u qmaill qmaill.crontab
  3. Install qareports.cron.d in root's crontab, e.g. by:
    cp qareports.cron.d /etc/cron.d/qmailanalog
    The third step will send an ALRM signal to the log service at midnight thus restarting logging with a new current log at the beginning of each day.

The second step will run the qareports script five minutes afterwards creating the reports for the past day, and updateing the monthly and yearly reports.


CategoryTips