Thursday, June 30, 2011

Webalizer - Apache web server log file analysis Tool

The Webalizer is a fast, free web server log file analysis program. It produces highly detailed, easily configurable usage reports in HTML format, for viewing with a standard web browser.


Install webalizer in ubuntu

sudo apt-get install webalizer
This will complete the installation.

Configuring Webalizer

Enable the apache2 hostname resolution for this you need to edit /etc/apache2/apache2.conf file and

sudo vi /etc/apache2/apache2.conf

HostnameLookups Off

into

HostnameLookups On

By default the package will install a daily cron job which will cause the system to process the logfiles once a day, it will always run after the default Apache logfile rotation, which means that instead of examining the logfile /var/log/apache2/access.log it will use the previous one /var/log/apache2/access.log.1

If you want to change to current apache log file you need to edit /etc/webalizer/webalizer.conf

sudo vi /etc/webalizer/webalizer.conf

change the following parameters

LogFile /var/log/apache2/access.log.1

to

LogFile /var/log/apache2/access.log

OutputDir /home/www/webalizer

Incremental yes

PageType htm*

PageType cgi

PageType php

HideURL *.gif

HideURL *.GIF

HideURL *.jpg

HideURL *.JPG

HideURL *.ra

IgnoreURL /taskbar*

Each parameter in Detail

LogFile /var/log/apache2/access.log

The option LogFile specifies the logfile to use with Webalizer. The default log file is supposed to be the access_log of Apache Web Server, but you can specifies a different one, like the one Squid Proxy Server makes named access.log if you use it in httpd-accelerator mode.

OutputDir /home/www/webalizer

The option OutputDir specifies the location of the output directory to use for the reports of Webalizer. All present and future report files generated by the Webalizer program will be hosted in this directory. It is recommended that you create this directory where your Apache web site resides.

Incremental yes

The option Incremental if set to Yes tells the program only to process partial logs file, and allows you to rotate your log files as much as you want without the loss of access information. It’s recommended to set this option to Yes.

PageType htm* cgi php

The option PageType specifies what file extensions you want Webalizer to consider as a page to count. Each added file extensions must be specified on its own line as shown in the Webalizer configuration file above.

HideURL *.gif *.GIF *.jpg *.JPG *.ra

The option HideURL specifies what kind of items such as graphic files, audio files or other non-html files to hide from the reports page. Each added item must be specified on its own line as shown in the Webalizer configuration file above.

IgnoreURL /taskbar*

The option IgnoreURL specifies URLs to be completely ignored from the generated statistics reports. This option can be used to ignore directories that are not important in our statistics reports. It’s also useful when you want to manage and class which URLs should be monitored and which should be ignored.

After configuring all the required options .Now you need to restart the Apache2 server using

sudo /etc/init.d/apache2 restart

Running Webalizer manually first time

Now it’s time to run the program to generate reports, html and graphics in the default Webalizer directory so that we can see them in our web browser interface. This step is required just the first time you install and use Webalizer, since it’s preferable to use a cron job to automate this task in the future. To run Webalizer manually, to generate reports, use the following command

webalizer

At this stage, we should verify that Webalizer is working on the system. To do that, point your web browser to the following address:

http://my-web-server/webalizer/. The my-web-server is the address where your Apache web server lives, and usage is the directory that host all the Webalizer reports files.

This works well for single sites, but if you have a group of websites all on the same machine you might need to make some changes.

The way that you handle multiple websites on one host is to place all the files beneath a common directory /home/www, such as:

/home/www/

www.domain1.com/logs/ and www.domain1.com/stats

www.domain2.com/logs and www.domain2.com/stats

Here we have two sites www.domain1.com, and www.domain2.com, each has its own logs,stats/ subdirectory where Apache places the logfiles and stat files.

To handle this simply you merely copy the default webalizer.conf file from /etc into each of the log directories:

cp /etc/webalizer.conf /home/www.domain1.com/logs

cp /etc/webalizer.conf /home/www.domain2.com/logs

Now if you make the changes to the configuration file so that each one has:

Logfile access.log

OutputDir ../stats/

You can update the stats by running

cd /home/www/www.domain1.com/logs

webalizer -q

cd /home/www/www.domain2.com/logs

webalizer -q

(The -q flag merely makes the program run quietly).

These two commands can be placed inside a shell script and invoked automatically be a cron job belonging to a user who can write to the stats directory - and you can remove the default job by running

rm /etc/cron.daily/webalizer

No comments:

Post a Comment