I’ve always been a big fan of AWStats for doing my daily log file analysis. It produces nice clean reports, and it’s fairly easy to configure too. The downside on Windows is that one has to install Activestate Perl. This only takes a couple of minutes, though. So, I’m going to cover how to install Perl on IIS 6, and then, how to setup your AWStats.conf file to work with IIS 6.
Installing Perl
Here’s the direct link to the Perl binary for Windows. http://www.activestate.com/Products/Download/Download.plex?id=ActivePerl
Grab the MSI version. GO ahead and run the install (you may want to reconfigure the location that the installer is targeted to.
Once Perl is installed, you’ll need to setup a Web Service Extension mapping in IIS. So, go ahead and open up IIS Manager (start>run>inetmgr), and then point to Web Service Extensions. Right click, and go to Add New Web Service Extension. Give it a useful name, i.e. Perl. Then, click Add, and browse to your Perl binary (Perl.exe). There’s a crucial extra piece here – tagging a “%s” %s on the end. For example: ‘D:\Perl\bin\Perl.exe “%s” %s’.
When the Perl installer was run, it should have setup the script mapping in the IIS home directory config, but if not, you’ll have to do that too. Right click the virtual directory/application/website you want to configure the Perl scripts for, go to the home directory tab, and then click Configuration down towards the bottom. If *.pl isn’t in the list, click add, and then put the same command in for executable as you did in the Web service extension (i.e. D:\Perl\bin\Perl.exe “%s” %s’). The extension is .pl, and go ahead and limit verbs to ‘GET,HEAD,POST’. Finally, check off script engine and verify that file exists.
That’s in for Perl, PHP should be similar, but I haven’t tried it yet.
The AWStats Setup
Now that Perl is installed, we can get AWStats all setup. Step one is to make a directory for it somewhere, under wwwroot is probably a good choice. Go into IIS Manager, and make an application out of the directory (click Create on the Home Directory tab). Next to Execute Permissions, select Scripts and Executables from the dropdown.
Step two is configuring the AWStats.conf file and IIS logging. Let’s tackle IIS Logging first. Right click the website to be logged, grotto properties, and then on the Configuration tab, check off Enable Logging (if it isn’t already). Select W3C Extended Format from the dropdown, and then click Properties. Select Daily logging, and then point the log files path elsewhere if you like. The Network Service account (or whatever account you configuring your AWStats application to run under will need permissions to this folder).
Proceed to the advanced tab and uncheck everything. There are certain items here that we’ll tick back off. Namely, the following items should be checked:
v Date (date)
v Time (time)
v Client IP Address (c-ip)
v Username (cs-username)
v Method (cs-method)
v URI Stem (cs-uri-stem)
v Protocol Status (sc-status)
v Bytes Sent (sc-bytes)
v Protocol Version (cs-version)
v User Agent (cs(User-Agent))
v Referrer (cs(Referrer))
Once this is done, go ahead and click OK all the way through to get back to the main screen. The next step is to delete all the old log files if they exist, as they’re not in the right format. The IIS end is now done, the final step is to setup the AWStats.conf file.
There are only a couple of items that need configuring in the AWStats.conf file for successful operation. The rest are covered in depth in the documentation, so, I won’t discuss them here. The first parameter to setup is your log file item. The only important part is the final piece at the end with the date time codes. For simplicity’s sake, I’ve included the entire line from my config file below:
LogFile="H:/Inetpub/LogFiles/W3SVC2024744933/ex%YY-24%MM-24%DD-24.log"
The config file and documentation say that one should specify LogFormat=2 for IIS. Unfortunately, IIS 6 does not follow this predefined format, so we’ll have to specify our own:
LogFormat="date time cs-method cs-uri-stem cs-username c-ip cs-version cs(User-Agent) cs(Referer) sc-status sc-bytes"
(that’s one line that got wrapped a bit)
The final parameter I’m going to cover here is DirData. This is a few down from LogFormat. Set this to the directory where you want AWStats to store its’ data files. I set mine to ./data, and place the folder under my AWStats root. Keep in mind, wherever this folder is, Network Service will need write permissions (if you schedule nightly file analysis, whatever account the task runs under will need write permissions).
I also have PurgeLogFile set to 1. This tells AWStats to delete a log file when it’s done analyzing it.
Scheduling Nightly Log file Analysis
AWStats only analyzes log files when told to do so. It can easily be toggled from the command line, and running a scheduled task to do this is the best solution. I have mine configured for 12:05 AM. I have a fairly small log file. For larger files, you’ll need to configure this to start earlier in the evening. Here’s the command my task runs:
H:\perl\bin\perl.exe H:\Inetpub\BrianCDesmond.com\wwwroot\awstats\awstats.pl -config=briandesmond.com –update
This is one line (wrapped). You’ll obviously need to reconfigure the physical paths to point to your Perl and AWStats installs.
?>
EDIT: With my LogFile config setting, you schould actually schedule AWStats to run after midnight, as it processes the previous day's log.
?>
?>