Wednesday, March 13, 2013

How to install SARG on Centos

How to install SARG on Centos | Fedora | RedHatSquid Analysis Report Generator (SARG) is a tool that allow you to view “where” your users are going to on the Internet. Sarg provides many informations about Squid users activities: times, bytes, sites, etc…
Note : Install and configure apache and squid on you server.  
Sarg Installation
[root@thelinuxwiki ~]# tar zxvf sarg-2.3.1.tar.gz

[root@thelinuxwiki ~]# cd sarg-2.3.1

[root@thelinuxwiki ~]# chmod a+x sarg-2.3.1/

[root@thelinuxwiki ~]# ./configure

[root@thelinuxwiki ~]# make

SARG Configuration
[root@thelinuxwiki ~]#cp /usr/local/etc/sarg.conf /usr/local/etc/sarg.conf.original

[root@thelinuxwiki ~]#rm /usr/local/etc/sarg.conf

[root@thelinuxwiki ~]#vim /usr/local/etc/sarg.conf

# This is sample configuration, that you need to setup
access_log /var/log/squid/access.log #squid access log location
graphs yes
graph_days_bytes_bar_color orange
title "Squid User Access Reports" # you need to change as your wish
temporary_dir /tmp
output_dir /var/www/html/sarg-reports #you can change location as your wish Create

Apache Conf file for sarg

[root@thelinuxwiki ~]# vim /etc/httpd/conf.d/sarg.conf

Alias /sarg /var/www/html/sarg-reports
<Directory /var/www/html/sarg-reports>
DirectoryIndex index.html
Order deny,allow
Deny from all
# add IP address you allow
Allow from 127.0.0.1 192.168.0. 10.210.8.
Allow from ::1
</Directory>

Now create a script to create daily statistics.

[root@thelinuwiki ~]# vim /root/sarglog.sh

#!/bin/bash
#Get current date
TODAY=$(date +%d/%m/%Y)
#Get one week ago today
YESTERDAY=$(date --date="1 day ago" +%d/%m/%Y)

/usr/local/bin/sarg -l /var/log/squid/access.log -o /var/www/html/sarg-reports/daily -z -d $YESTERDAY-$TODAY
exit 0

[root@thelinuxwiki ~]# chmod 775 /root/sarglog.sh


[root@thelinuxwiki ~]# sarg -x  (this command will generate report)

# run at 9:00 AM every day
[root@thelinuxwiki ~]# crontab -e
0 9 * * * /root/sarglog.sh

# Now you can access your squid reports and it will show like below 


http://localhost/sarg/ or http://youripaddress/sarg or http://127.0.0.1/sarg or 

http://127.0.0.1/sarg-reports