Monday, 21 May 2012

Setting up webalizer to track squid access

Introduction

Instead of browsing through the log file in /var/log/squid/access.log, a more convenient way is to configure webalizer. As I find it quite tedious and time consuming going through the log files as there are hundred or thousand of entries in there. Webalizer is a more user friendly and convenient way as it is accessible via a web browser and also there are graphs and charts that can display in a more presentable way and also, this can also be configured in a cron job for it to update the informations hourly.


Setup

1. Edit the file /etc/webalizer.conf

2. Locate "LogFile" in webalizer.conf and change it to LogFile /var/log/squid/access.log

3. Locate "DailyGraph" and change the graph settings based on your requirements.

4. Locate "TopSites" and change the settings based on your requirements. Just remove the # in front for the option that you need to log

5. Locate "AllSites" and change the settings.

6. Save and exit webalizer.conf file.

7. Now is to configure a cron file to automatically update the data on a hourly basis. cd to directory  /etc/cron.hourly  and create a file call squid.cron and enter the following to the file

#!/bin/bash
cd /var/log/squid
cat access* | /usr/bin/webalizer -F squid -o /var/www/usage/ -A 100 -C 100 -R 100 -S 100 -U 100 -e 100 -E 100 -Q

8. chmod 755 the squid.cron file

9. Do some browsing on the Internet using the squid proxy.

10. Manual execute the squid.cron file with a ./ in front and there should be some html files created by webalizer in /var/www/usage

11. Open up a browser and point the browser to the squid box with /usage to see the data.

As for me, since the box is a dedicated linux box just for serving proxy client, I configured apache web directory to /var/www/usage instead of /var/www/html
 with a password access. Below are the steps.

1.  cd to /etc/httpd/conf nad edit the file httpd.conf

2. Locate "DocumentRoot" and change the entry to DocumentRoot "/var/www/usage"

3. Locate <Directory "/var/www/html"> and change it to <Directory "/var/www/usage">

4. Change the AllowOverride None to AllowOverride Authconfig and also the following:

    AuthType Basic
    AuthName "Proxy Statistics"
    AuthUserFile "/var/www/usage/secure/.htpasswd"
    Require valid-user
    Order allow,deny
    Allow from all

</Directory>

5. Save then quit httpd.conf file and cd to /var/www/usage

6. Create a folder call secure

7. cd to secure folder and key in htpasswd -c .htpasswd (username) then it will prompt you to enter the password. Once you have enter the password, it will create a hidden .htpasswd file for in the secure folder and whenever you want to add another user to access the usage page, key in htpasswd .htpasswd (username) without -c.

8. Lastly restart the httpd service by issuing the command service httpd restart

9. Open up an internet browser and point to your server ip address and it should now prompt you for username and password, once you have entered a valid user account then it will directly show you the index file reside in /var/www/usage.



No comments:

Post a Comment