Mac OS X Server has tools to monitor trends in network traffic and look at your log files, but I’ve always wanted easy to read, detailed stats for my web server.
AWStats is a free powerful and featureful tool that generates advanced web, streaming, ftp or mail server statistics, graphically. This log analyzer works as a CGI or from command line and shows you all possible information your log contains, in few graphical web pages. It’s open source and not too difficult to set up.
(This has been tested on OS X Server 10.3.9 and 10.4.4)
1. Go to: awstats.sourceforge.net and download the latest, greatest version (as of now, awstats-6.5).
2. un-tar it.
3. move everything to:
/Library/WebServer/awstats/
4. copy the contents of awstats/wwwroot/cgi-bin/ to /Library/WebServer/CGI-Executables/
This includes:
awredir.pl
awstats.model.conf
awstats.pl
/lang/
/lib/
/plugins/
5. copy the rest of the contents of awstats/wwwroot/ into:
/Library/WebServer/Documents/
This includes:
/classes/
/css/
/icon/
/js/
6. Edit:
/library/webserver/awstats/tools/awstats_updateall.pl
find:
my $DIRCONFIG = “/etc/awstats”;
change to:
my $DIRCONFIG = “/library/webserver/CGI-Executables”;
find:
my $Awstats=’awstats.pl’;
change to:
my $Awstats=’/library/webserver/CGI-Executables/awstats.pl’;
save awstats_updateall.pl
7. run the awstats_configure.pl script to do several setup actions:
cd /Library/WebServer/awstats/
sudo perl /Library/WebServer/awstats/tools/awstats_configure.pl
at the prompt:
-----> Need to create a new config file ?
Do you want me to build a new AWStats config/profile
file (required if first install) [y/N] ?
..hit ‘y’ and ‘enter’.
at the prompt:
-----> Define config file name to create
What is the name of your web site or profile analysis ?
Example: www.mysite.com
Example: demo
Your web site, virtual server or profile name:
..enter your site name:
YourServerName.com
..then hit ‘enter’ two more times when prompted.
8. edit the config file it created at:
/library/webserver/awstats/wwwroot/cgi-bin/awstats.YourServerName.com.conf
find:
LogFile=”/var/log/httpd/mylog.log”
change to:
LogFile=”/var/log/httpd/access_log”
(..or whatever the virtual host’s log file name is. Check Server Admin if you’re unsure.)
find:
LogFormat=1
Possible values: 1,2,3,4 or “your_own_personalized_log_format”
# 1 – Apache or Lotus Notes/Domino native combined log format (NCSA combined/XLF/ELF log format)
# 2 – IIS or ISA format (IIS W3C log format). See FAQ-COM115 For ISA.
# 3 – Webstar native log format.
# 4 – Apache or Squid native common log format (NCSA common/CLF log format)
# With LogFormat=4, some features (browsers, os, keywords…) can’t work.
I believe OS X Server’s default is “common” – so for the first run, you may have to set LogFormat=4. More on that below. **
find:
HostAliases=”
..and add any aliases or ip addresses for this site.
find:
DirData=”/var/lib/awstats”
change to:
DirData=”.”
(The comment suggests that this is supposed to be the default.. but it doesn’t seem to be.
“.” means the same directory as awstats.pl.. in our case: /Library/WebServer/CGI-Executables/)
find:
DirCgi=”/awstats”
change to:
DirCgi=”/cgi-bin”
find:
DirIcons=”/awstatsicons”
change to:
DirIcons=”/icon”
OPTIONAL CHANGES:
AWStats can purge log file, after analyzing it. Note that AWStats is able
to detect new lines in a log file, to process only them, so you can launch
AWStats as often as you want, even with this parameter to 0.
find:
PurgeLogFile=0
change to:
PurgeLogFile=1
find:
DefaultFile=”index.html”
change to:
DefaultFile=”index.php index.html”
(or whatever your default file type is)
find:
NotPageList=”css js class gif jpg jpeg png bmp ico swf”
add any other file types you don’t want to count toward “page hits”:
NotPageList=”inc css js class gif jpg jpeg png bmp ico swf”
find:
FirstDayOfWeek=1
Change this to “0” if you want the week report to start on sunday instead of the default monday.
Make any other edits you’d like and save the config file.
9. Move this file to your /library/webserver/CGI-Executables/ directory:
sudo mv /library/WebServer/awstats/wwwroot/cgi-bin/awstats.YourServerName.com.conf /library/webserver/CGI-Executables/awstats.YourServerName.com.conf
10. Either copy the /icon directory into your website’s root directory or create a symlink to a common /icon directory shared by all of your virtual hosts:
ln -s ../icon icon
11. run it:
sudo perl /Library/WebServer/awstats/tools/awstats_updateall.pl now
Your stats should now be available at:
http://www.YourServerName.com/cgi-bin/awstats.pl?config=YourServerName.com
12. For ease of use, I set up a redirect page at:
http://www.MyServerName.com/stats/
..that sends you to:
http://www.MyServerName.com/cgi-bin/awstats.pl?config=MyServerName.com
Repeat steps 7-12 for each additional virtual host.
Automate the update with a cron job.
I used CronniX to add:
0 * * * * root /Library/WebServer/awstats/tools/awstats_updateall.pl now
This will update the stats for all of the sites you’ve set up this way at the top of the hour, every hour.
** APACHE LOG CONFIG:
OS X Server 10.3.9 and 10.4.4 both seem to use the “common” apache log configuration by default. I’m interested in getting more information than that provides (browsers, os, search keywords, etc), so I switched to the “combined” format:
a. Using Server Admin, click on “web” > “settings” > “Sites”.
b. For each web site defined, click on the domain name, click the “edit” button (pencil icon at the bottom of the screen). Under the “logging” tab: change value for “format” from “common” to “combined”. Click the “back” arrow and do the same for your other sites.
c. Click save.
d. Since we’ve changed the log format, we need to re-edit the awstats config file:
/library/webserver/CGI-Executables/awstats.YourServerName.com.conf
find:
LogFormat=4
change to:
LogFormat=1
save the config file.
e. If you didn’t previously set up awstats to purge the log file after it uses it (PurgeLogFile=1), you may want to archive the old log file now and start fresh with a blank one.
The default directories AWStats tried to put things in didn’t always work for me. I had to play around with my setup before I came up with these instructions. This worked for me, running multiple virtual hosts on both OS X Server 10.3.9 and 10.4.4. If you have any corrections or suggestions to add to this, I’d like to hear any feedback.
Hey man, great page. Due to my rolling logs, it barfs. I shoved in a wildcard for the awstats vhost pointer:
Error: Couldn’t open server log file “/var/log/apache2/access_mydomain_log*” : No such file or directory
I now have 3 logs from restarting apache:
access_mydomain_log.1373049123
Any idea how I can get that workin?
access_mydomain_log.* is my first trick, but the first wildcard would have worked.
Cheers
OK I have it on a launchd hourly update now.