Real statistics on your site using AWStats


It is surprising how much information you can get from your readers activity. I like asking my server what country you come from, how much did you stay in the last visit, how did you arrive here, what is the most viewed page, how much bandwidth I am wasting, what spiders are coming in, what keysearches made you arrive here, why am I getting 404 errors.... and a long long etcetera.

There are many statistics tools around that you can install in your sever and even you can find services to ease that pain. But a nice (and free) way of getting statistics information is using AWStats, and if you have a server with multiple sites, then you don't have excuse.

Whether if you are a professional or a eager user, AWStats deserves a try. It reads your unparsable Apache logs for you and uses that information to confeccioante a global vision of what's been going on. It doesn't matter what product are you using to serve your pages (Zope, Plone, PHP...) while you are logging into apache...

Exploring the guts

When you download and install awstats (read the doc inside the package to achieve this) you get a hierarchy of directories and files, similar to this one. (These paths are orientative): A directory that stores the application itself:

|-- docs
|-- tools
`-- wwwroot
    `-- cgi-bin

And a directory that stores the configuration files for your sites.

|-- CustomLog
|-- awstats.model.conf

The application can work both through the shell, building static pages or through the web using CGIs. You don't have to choose for one or the other, but I decided to only use one. The shell option ...and I exclude retrieving the stats with CGIs with something like because I don't want to activate the perl module in my site. To ensure this, I removed the following from my httpd.conf file (it was inserted during the install at the bottom of the file):

# Directives to allow use of AWStats as a CGI
Alias /awstatsclasses "/usr/local/awstats/wwwroot/classes/"
Alias /awstatscss "/usr/local/awstats/wwwroot/css/"
Alias /awstatsicons "/usr/local/awstats/wwwroot/icon/"
ScriptAlias /awstats/ "/usr/local/awstats/wwwroot/cgi-bin/"
# This is to permit URL access to scripts/files in AWStats directory.#
<Directory "/usr/local/awstats/wwwroot">
    Options None
    AllowOverride None
    Order allow,deny
    Allow from all

... and I added to my crontab a script containing a simple set of instructions. One sentence for updating the awstats database (or creating it for the first time) and another for generating the html files.

cd /usr/local/awstats/
perl wwwroot/cgi-bin/ -update
perl tools/ \ \
     -dir=/output/dir -lang=en
(last sentence splitted in three lines)

where the /output/dir is where the static html files are created and lang=en is the language for the files. If neither of this options are chosen, the default options are loaded, explore the documentation for more options. Note that AWStats supports many languages. If you have multiple sites in your server you should notice that all the web activity is stored in the same access log file by default, to prevent this, create a custom log file for every Virtual server. This is done in seconds by editing the httpd.conf file and adding a line like this

CustomLog /path/to/access_log combined

Then, check that /path/to/access_log is writeable by apache user and restart the service. Visit the AWStats homepage for more screenshots, demos, docs and other useful resources. The complete process for installing and configuring AWStats is not easy if you are a newbie, so you'll probably will need visiting it, but it's worth a try.

Providing your site with a statistics monitoring tool is quite interesting. There are many tools and external services to accomplish that, but if you have a server I think the best option is using AWStats. I played a bit with it and now my litlle experience is pasted here.