WWW Usage Statistics
We keep record how much and by who our web server is visited. These usage pages show how much and who accesses which web pages on our server.
You can have your own usage statistics for your own web pages created in the same way using webalizer.
The web server log files are rotated weekly on the same day ... look at the time stamps of the rotated logs to learn when. The log files contain a mixture of IP addresses and host names: whenever the web services needs the hostname of the web client (e.g. to check access rights), that hostname is logged. Otherwise just the IP address of the request is logged.
The easiest way of building your statistics is using a script that is called weekly by crontab.
Do not use a time between 2am and 3am in this crontab, since this will get you in trouble twice a year when daylight saving time begins/ends !
Basic way to use webalizer
To use webalizer, you need to extract from the main log file the entries that you want statistics for (e.g. by means of a simple grep command) and send that as input to webalizer :
egrep -i 'what-you-want' /path/to/the/server/log/file > thisweek.log
webalize -your -options thisweek.log
The above command will analyze the log file and create/update the webalizer statistics in the current directory (so make sure to execute it in the right directory!).
The easiest way is probably to create a crontab script that does this weekly, after the web server log files are rotated (see above).
It is probably best to make/do an incremental analysis, whereby the current weekly log file is parsed and the monthly statistics are generated correctly. The statistics for the current month are of course incomplete and will be added to the following weeks.
For more information, please consult the man page.
Pay special attention to the following options:
- -D DNSCache : which cache file to use for resolving IP addresses in the log file to host and domain names
- -N number : how many threads to use for resolving IP addresses
- -n : the title of the statistics as part of the `Usage statistics for ...'
- -p : do an incremental update
- -o : directory to put the result in
Real world example
If you want to set up webalizer statistics for your own personal web directory, you can do so in the above and below examples with:
- what-you-want = '/(~|%7E)firstname.lastname/'
- /path/to/the/server/log/file = /cw/w3logsX/people-access.log.1
The X in w3logsX above (and w3peopleX below) is either 1 or 2, depending on the exact web server your personal web directory is located on.
The examples below require some additional configuration:
- /path/to/your/webalize/log/file = /home/loginname/Webalizer/$date.log.gz (i.e. keep the logs by date)
- /path/to/your/webalizer/statistics/directory = /cw/w3peopleX/firstname.lastname/public_html/Webalizer
- http://server.name/url/to/webalizer/statistics = http://people.cs.kuleuven.be/~firstname.lastname/Webalizer
Easier way to use webalizer
You can also use or have a look at /cw/www/USAGE/webalize.wrapper (and/or /cw/www/USAGE/webalize) ... this makes a lot of things easier because you don't have to worry about the details.
Example use: create a crontab entry with the following commands:
egrep -i 'what-you-want' /path/to/the/server/log/file | \ /cw/www/USAGE/webalize.wrapper \ -c /path/to/your/new/webalize/log/file \ /path/to/your/webalizer/statistics/directory \ http://server.name/url/to/webalizer/statistics
The above command is wrapped to clearly describe the components:
- select the log entries you are interested in from the server log file
- and feed them to the webalizer wrapper script while giving:
- the log file where these log entries will be kept (which should not be in your web-directory but instead in your home directory or so)
- the statistics directory, which should be in your web-directory
- the URL that corresponds with that statistics directory
Alternative configurations:
- re-use/overwrite the same log file (with your specific log entries, i.e. the result of your egrep) each week instead of creating and keeping a (new) log file each week: use -f instead of -c:
egrep -i 'what-you-want' /path/to/the/server/log/file | \ /cw/www/USAGE/webalize.wrapper \ -f /path/to/your/existing/webalize/log/file \ /path/to/your/webalizer/statistics/directory \ http://server.name/url/to/webalizer/statistics
/cw/www/USAGE/webalize.wrapper \
/path/to/the/server/log/file \
/path/to/your/webalizer/statistics/directory \
http://server.name/url/to/webalizer/statistics
For more information, see:
- /cw/www/USAGE/webalize.wrapper --help
- /cw/www/USAGE/webalize --help
- /cw/www/USAGE/README
Advanced way to use webalizer
You can even take it yet a step further and combine several webalizer statistics into one configuration file in a single crontab entry:
/cw/www/USAGE/webalize.targets /path/to/webalize.targets.conf
For more information, see:
- /cw/www/USAGE/webalize.targets --help
The above examples can be configured in the target configuration file as:
defaulttargets='example1 example3'
function getVars {
case "$1" in
example1)
serverlog=/path/to/the/server/log/file
regex='what-you-want'
logfile=/path/to/your/new/webalize/log/file
webdir=/path/to/your/webalizer/statistics/directory
url=http://server.name/url/to/webalizer/statistics
;;
example2)
serverlog=/path/to/the/server/log/file
regex='what-you-want'
overwrite=yes
logfile=/path/to/your/existing/webalize/log/file
webdir=/path/to/your/webalizer/statistics/directory
url=http://server.name/url/to/webalizer/statistics
;;
example3)
logfile=/path/to/the/server/log/file
webdir=/path/to/your/webalizer/statistics/directory
url=http://server.name/url/to/webalizer/statistics
;;
esac
}
Do notice that example2 is configured as an `extra' target, which will only be processed if you specify it as an explicit argument when calling /cw/www/USAGE/webalize.targets.
extra.conf
Both the easier and the advanced way of using webalizer, use a configuration file extra.conf in your webalizer statistics directory where you can put extra configuration items to control the exact way the standard webalize command behaves.
The first such configuration item you should consider is the title that appears at the top of the generated web pages - configure it by means of the HostName configuration item.
If /cw/www/USAGE/webalize.targets creates the statistics directory it will also create a default extra.conf.

