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 {
weekly
missingok
rotate 52
compress
delaycompress
notifempty
sharedscripts
prerotate
/usr/lib/cgi-bin/awstats.pl -config=www.claudiokuenzler.com > /dev/null
endscript
postrotate
/etc/init.d/apache2 reload > /dev/null
endscript
}
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).
No comments yet.
AWS Android Ansible Apache Apple Atlassian BSD Backup Bash Bluecoat CMS Chef Cloud Coding Consul Containers CouchDB DB DNS Database Databases Docker ELK Elasticsearch Filebeat FreeBSD Galera Git GlusterFS Grafana Graphics HAProxy HTML Hacks Hardware Icinga Influx Internet Java KVM Kibana Kodi Kubernetes LVM LXC Linux Logstash Mac Macintosh Mail MariaDB Minio MongoDB Monitoring Multimedia MySQL NFS Nagios Network Nginx OSSEC OTRS Office PGSQL PHP Perl Personal PostgreSQL Postgres PowerDNS Proxmox Proxy Python Rancher Rant Redis Roundcube SSL Samba Seafile Security Shell SmartOS Solaris Surveillance Systemd TLS Tomcat Ubuntu Unix VMWare VMware Varnish Virtualization Windows Wireless Wordpress Wyse ZFS Zoneminder