In this post  we'll see installing and configuring SARG for your network to get squid user's internet usage reports and bandwidth. So that we can easily analyse the usage of bandwidth, highest usage websites and access denied websites and the time site accessed.

First download latest sarg package from source forge 
Now install the packages like, httpd, gcc, gd, gd-devel, perl-GD etc...

[root@web]# yum install httpd gcc gd gd-devel perl-GD -y

Once required packages installed, untar the downloaded sarg package and compile and install.

[root@web]# cd /root/Downloads
[root@web]# tar -xvzf sarg-2.3.5.tar.gz
[root@web]# cd /root/Downloads/sarg-2.3.5
[root@web]# ./configure
[root@web]# make
[root@web]# make install

You'll see all the sarg related file paths on the terminal if the you ran make install successfully with out errors.

Now edit config file to set below things

  • Access logs path
  • Output directory
  • Date Format
  • Overwrite report for the same date 
[root@web]# vim /usr/local/etc/sarg.conf

access_log /var/log/squid/access.log
output_dir /var/www/html/squid-reports


##Date format in reports: e (European=dd/mm/yy), u (American=mm/dd/yy), w (Weekly=yy.ww)##

date_format e
overwrite_report yes

Since i user Euopean format i  used "e", date format is  your wish.
ow restart apache and run sarg to generate reports. To check the reports enter 192.168.x.x/squid-reports



To automate the sarg to generate reports in given span of time set a cron job. Ex. for every one hour.

[root@web]# crontab -e

* */1 * * * /usr/local/bin/sarg -x

If you want to customize the URL for sarg like 192.168.x.x/sarg  instead of 192.168.x.x/squid-reports, edit below file.

[root@web]# vim /etc/httpd/conf.d/squid-reports.conf



Alias /squid-reports /var/www/html/squid-reports

<Location /var/www/html/squid-reports>
   Options Indexes
    Order deny,allow
    Allow from all
    # Allow from .example.com
</Location>


Just replace /squid-reports with the word you wish to use. In my case i want it to be 192.168.x.x/sarg so i edited like below

Alias /sarg /var/www/html/squid-reports

<Location /var/www/html/squid-reports>
   Options Indexes
    Order deny,allow
    Allow from all
    # Allow from .example.com
</Location>


Restart the apache and check with the new URL in the browser 192.168.x.x/sarg

gil...