AWStats for a load balanced environment

A couple of FAQs from the official AWStats doc addresses the question: How do I use AWStats in a load-balanced environment?

FAQs are here and here.

So this turned out to be fairly easy to implement.

Going up to same shared storage I put my static web files on (let’s call it “/nas1”), I created a “logs/n1” and “logs/n2” directory to hold the access logs from my two load-balanced web servers. The Apache config looked something like this:

Web Server 1:

CustomLog /nas1/logs/n1/mysite.example.com-access_log combined

Web Server 2:

CustomLog /nas1/logs/n2/mysite.example.com-access_log combined

[Note that AWStats really prefers using the “combined” log format, which I have to modify slightly for my environment because of our reliance on x-forwarded-for to get the real addresses of clients passing through the load balancer.]

Then I modified the awstats conf file for the site (awstats.mysite.example.com.conf) under /etc/awstats to invoke the logresolvemerge.pl tool for aggregating these logs on the fly whenever awstats does an update:

LogFile="/usr/share/awstats/tools/logresolvemerge.pl /nas1/logs/n1/mysite.example.com-access_log /nas1/logs/n2/mysite.example.com-access_log |"

That’s all on one line in real life.

Once everything was in place (and I had some logged activity to analyze), I did an update to the awstats database to check for errors:

/usr/share/awstats/wwwroot/cgi-bin/awstats.pl \
-config=mysite.example.com -update

The output should have shown that the script processed the piped command against both log files. Instead, in my case a small typo in the log file path caused awstats.pl to keep throwing an error until I fixed it. With the error fixed the db updated and I now had awstats’s analysis of the aggregated log data.

This entry was posted in System Administration, Systems Analysis, Web on by .

About phil

My name is Phil Lembo. In my day job I’m an enterprise IT architect for a leading distribution and services company. The rest of my time I try to maintain a semi-normal family life in the suburbs of Raleigh, NC. E-mail me at philipATlembobrothersDOTcom. The opinions expressed here are entirely my own and not those of my employers, past, present or future (except where I quote others, who will need to accept responsibility for their own rants).