Complete Virtual Mail Server/AWStats

Introduction
Even though postfix provides logs, it would be much nicer to have it graphically displayed. is a package that takes such logs and displays graphs for them. Because AWStats main purpose is processing Apache log files this will have two consequences. Firstly AWStats will also be used to process Apache logs. Secondly postfix logs need to be filterd for AWStats to work. After the apache logs have been processed and proven to work, they could be removed once AWStats for mail works properly.

Installation
AWStats is a webapp and thus gets installed in two steps. If it hasn't been emerged already, it needs to be emerged.

Then it needs to be installed in a host of its own. AWStats will live in its own webhost, stats.example.com.

After webapp-config has completed it will output some instructions how to prevent AWStats from being accessed by unauthorized users. In this document only basic authentication will be covered.

Apache Configuration
Since Apache will be serving the content AWStats generates, it needs to be given some directions on how to do so. AWStats generates its information from the apache log files. They need to agree on certain things. A default AWStats setup wants the combined LogFormat. A slightly more extended version is the vhost LogFormat which will be used. It is identical to the combined format with the addition of mentioning the vhost name that was used to access the site. The awstats configuration file will be changed later to match this setting.

Apache will next need be told how to server the AWStats files. This will be done in the file.

And a needs to be created accordingly.

After restarting apache, http://stats.example.com/awstats/awstats.pl should come up with some errors about missing configuration files, but this means that AWStats is actually running and thus Apache has been set up correctly.

AWStats Configuration
AWStats needs a configuration file on how and what to log. The default configuration file needs to be copied to and then edited.

If the has been set, the geoip plugin has to be enabled in the configuration file as well.

Data collection
AWStats needs to parse the apache config file. This is done via the awstats script from the commandline.

If this has run satisfactory it can be placed into an hourly cronjob. If the website is extremly busy, or quicker updates are required a custom cronjob needs to be written.

For cron to accept this script, it needs to be executable.

If logrotate is being used to rotate apache logs, logs should be parsed by awstats before the log is rotated. Logrotate has the prerotate command which is envoked after the sharedscripts command.

Apache Configuration
Since parsing the mail stats happens by the same AWStats instance, Apache is already setup correctly. In doubt re-check the previous section.

AWStats Configuration
For AWStats to be able to processes the file it needs to convert them to a more suitable format. Included in the AWStats package is the perl script. There are alternatives in pure C if the perl script is to heavy. It should suffice however for nearly all to get started. First a copy needs to be made again from the default awstats.model.conf file.

Then it needs to be changed to point to at the very least to the mail log files rather then the apache log files.

Data collection
AWStats now is ready to parse the log file. It can be run manually at intervals, or to verify it is setup correctly.

If there are errors, the settings should be revised. To have AWStats run automatically, the previous cronjob can be modified or extended to gather mail statistics.

And finally, also the mail log can parsed before its logs get rotated.

To access the stats from the mail log, a slightly different url will have to be used, namely the specific config file needs to be supplied,.