I’ve finally found some time to get awstats setup to crunch my Glassfish logs. This turned out to be a little trickier than I expected, so I though I’d write up some gotchas incase other are walking the same path.
First up, you need to get Glassfish to write log files in a suiteable format for awstats. Glassfish gives you a nice admin GUI in /Configuration/HTTP Service/Access Logs where you can change the format of what’s logged. If you access this page, then click the Help menu, you’ll get a list of available parameters that you can insert.
Awstats likes the NCSA combined/XLF/ELF format, which you can whip up in Glassfish using the following format:
%client.name% %datetime% %request% %status% %response.length% %header.referer% %header.user-agent%
This is pretty close. It’ll get you to something like:
"123.456.7.89" "13/Nov/2006:14:22:25 +1000" "GET /common/images/feed-icon-16x16.png HTTP/1.1" 200 764 "[http://www.bytecode.com.au/passwordsafeswt/](http://www.bytecode.com.au/passwordsafeswt/)" "Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8.0.7) Gecko/20060911 Camino/1.0.3"
But we’re still not quite there. Those quotes around the first ipaddress and date fields will cause you grief. So you need to strip them off. I’m using sed with a command like:
LogFile="sed -e 's/"([0-9.]*)"/1/g' -e 's/"([^"]*+1000)"/[1]/g'/path/to/glassfish/domains/domain1/logs/access/www.bytecode.com.au_access_log.%YYYY-0-%MM-0-%DD-12.txt |"
That guy will strip the quotes from the ipaddress, then reformat the datestamp to have no quotes and replace with square brackets. You’ll need to change the +1000 to whatever your GMT offset is as it appears in your logs.
Once you’ve done all that, you’re good to go. Setup a cron job to run awstats_updateall.pl early in the morning, then follow it with a awstats_buildstaticpages.pl to dump your stats into some docroot location and you’re ready to crunch.
Voila! Glassfish logs with funky stats.
Enjoy!