Using awstats in combination with logrotate

Written by - 0 comments

Published on - Listed in Linux Internet

Situation: You have your website running on an Apache web server and you're using awstats for your web statistics. You have a daily cronjob which starts the awstats script like this:


The above command launches the awstats script with a config /etc/awstats/ 

But as the log file grows and grows, you want of course to rotate the log files.

Problem: When you rotate the log file, awstats doesn't know about it and looses all visitor data now stored in the rotated access log. And afaik, there is no config parameter to tell awstats about a location/path of a rotated log file.

To solve that issue, awstats can be called during the log rotation phase:

cat /etc/logrotate.d/
/var/log/apache2/*.log {
rotate 52
        /usr/lib/cgi-bin/ > /dev/null
        /etc/init.d/apache2 reload > /dev/null

Besides the obvious logrotate options, the magic happens in the prerotate section: Right before rotating the log file(s), launch the awstats command and analyze the access log.
After the log was rotated, the postrotate section starts and reloads Apache (to prevent the Apache process of writing into the previous log file's inode).

Granted, during the time awstats is running, there could be several new hits on the website and therefore new entries in the access log. But on my site the lost statistics are marginal (and honestly not that important).

Add a comment

Show form to leave a comment

Comments (newest first)

No comments yet.