Header RSS Feed
If you only want to see the articles of a certain category, please click on the desired category below:
ALL Android Backup BSD Database Hacks Hardware Internet Linux Mail MySQL Monitoring Network Personal PHP Proxy Shell Solaris Unix Virtualization VMware Windows Wyse

Using awstats in combination with logrotate
Monday - Jun 23rd 2014 - by - (0 comments)

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:

/usr/lib/cgi-bin/awstats.pl -config=www.claudiokuenzler.com

The above command launches the awstats script with a config /etc/awstats/awstats.www.claudiokuenzler.com.conf. 

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/www.claudiokuenzler.com
/var/log/apache2/www.claudiokuenzler.com/*.log {
rotate 52
        /usr/lib/cgi-bin/awstats.pl -config=www.claudiokuenzler.com > /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.

Go to Homepage home
Linux Howtos how to's
Monitoring Plugins monitoring plugins
Links links

Valid HTML 4.01 Transitional
Valid CSS!
[Valid RSS]

6938 Days
until Death of Computers