Friday, November 9, 2012

Monitoring an Amazon Web Service Image

Peter Funk from our Advantage engineering team has been using Amazon Web Services (AWS) to host a project he has been working on. He was looking for a tool to monitor the activity on his site. Peter found a tool that met his needs so he asked me to share his thoughts about it. I was all to happy to post this information for him.

Now that I have an application (website) up and running with the Advantage Web Platform I wanted to monitor the traffic. Primarily I want to be on the lookout for any hacking attempts but also I am curious how my users are accessing the site. Searching around for website monitoring tools quickly led me into the world of log analyzers.

To have a complete picture of your site’s traffic you must log all activity to some sort of log file or database. With Apache this functionality exists in the log_config_module which is enabled by default. This module will log all activity to the access.log file (by default in the apache\logs directory). Although all the information I needed was in the access.log it wasn’t in a useable form. That’s where the log analyzer comes in.

There are quite a few log analyzers available on the web these days. I wanted one that works with Apache, provides real-time statistics, has a wealth of information including graphs, and is free. Eventually I found the AWStats project hosted on sourceforge.net.

clip_image001

AWStats met all my requirements and has been working well for me so far. It is written in Perl and is accessible from any browser. It is pretty simple in that it processes the access.log, creates a report with a summary of all the log information, and then displays the information in an informative and useful way. You can see a demonstration of AWStats in action using this link.

For up-to-date statistics AWStats must process the access.log to refresh the summary report. This can be done on demand or on a schedule (Windows task manager or Linux cron job). So far I’ve been using the on-demand approach (see AllowToUpdateStatsFromBrowser in the AWStats documentation) but creating a scheduled task may work better for you. When I want to view the current statistics I simply bring up the awstats page and click the Update Now link. A few seconds later I can view the report with current information.

Make sure you have a Perl interpreter installed on your server before installing AWStats. I recommend the Activestate interpreter for Windows.

Installing AWStats is simple. Just follow the instructions and it will create a project for your site and adjust any configuration settings. You will likely need to restart Apache after the installation is complete. You might also need to tell Apache which Perl interpreter to use. On Windows you can simply tell Apache to look into the registry for which application is assigned to the .pl file extension. Do this by adding the following line to your httpd.conf file:

ScriptInterpreterSource registry

By default the AWStats page is visible to anyone by your web server. You can limit that access to an IP address or domain. In your httpd.conf file look for the directory entry that points to your AWStats/wwwroot folder. It should be at the bottom of the file. There you can limit the access via the “Allow from” option.

One issue I had with Google’s chrome browser was with the HTML frames that AWStats.pl creates. For some reason chrome didn’t like the frames so I had to disable them with the UseFramesWhenCGI setting in the awstats conf file for my website:

UseFramesWhenCGI=0

In conclusion I am very happy using AWStats to keep an eye on my website. It gives me a good view into how people are using my website. I can already see which URLs are used the most and look for ways to optimize them. I can also see which browsers are used the most which helps me test and tailor my website to provide the best experience for the most people.

No comments: