Install SARG (Squid Analysis Report Generator) at Ubuntu

SARG is a very useful tool for us, which is primarily to observe the access statistics on the site’s URL Proxy Server. To report on the SARG configuration we can fit the needs of our report, whether it is for daily, weekly or monthly.

The first download sarg in http://sarg.sourceforge.net/sarg.php, but you can download it through konsole :

root@server:~# apt-get install sarg

After SARG installed, do not forget to configure sarg.conf with your preferred editor:

root@server:~# vim /etc/squid/sarg.conf

– By pressing the letter I add the following line, Please change the configuration in accordance with Uncomment the following : —

language English
access_log /var/log/squid/access.log
graphs yes
graph_days_bytes_bar_color orange
title “Squid User Access Reports”
font_face Tahoma,Verdana,Arial
header_color darkblue
header_bgcolor blanchedalmond
font_size 9px
background_color white
text_color #000000
text_bgcolor lavender
title_color green
temporary_dir /tmp
output_dir /var/www/squid-reports
resolve_ip
user_ip no
topuser_sort_field BYTES reverse
user_sort_field BYTES reverse
exclude_users /etc/squid/sarg.users
exclude_hosts /etc/squid/sarg.hosts
date_format u
lastlog 0
remove_temp_files yes
index yes
index_tree file
overwrite_report yes
records_without_userid ip
use_comma yes
mail_utility mailx
topsites_num 100
topsites_sort_order CONNECT D
index_sort_order D
exclude_codes /etc/squid/sarg.exclude_codes
max_elapsed 28800000
report_type topusers topsites sites_users users_sites date_time denied auth_failures site_user_time_date downloads
usertab /etc/squid/sarg.usertab
long_url no
date_time_by bytes
charset Latin1
show_successful_message yes
show_read_statistics yes
topuser_fields NUM DATE_TIME USERID CONNECT BYTES %BYTES IN-CACHE-OUT USED_TIME MILISEC %TIME TOTAL AVERAGE
user_report_fields CONNECT BYTES %BYTES IN-CACHE-OUT USED_TIME MILISEC %TIME TOTAL AVERAGE
topuser_num 0
site_user_time_date_type table
download_suffix “zip,arj,bzip,gz,ace,doc,iso,adt,bin,cab,com,dot,drv$,lha,lzh,mdb,mso,ppt,rtf,src,shs,sys,exe,dll,mp3,avi,mpg,mpeg”

– save by pressing :wq and Enter

Next to run sarg use the command :

root@server:~# sarg

In order for these commands is run automatically so that we execute the syntax via cron. In orderreportnya more interesting then we divide by day, week and month. The trick is as follows:

Daily Report :

root@server:~# vim /usr/sbin/sarg-daily-report

– By pressing the letter i, Please insert : –

TODAY=$(date +%d/%m/%Y)
YESTERDAY=$(date –date “1 day ago” +%d/%m/%Y)
sarg /var/log/squid/access.log -o /var/www/squid-reports/daily -z -d $YESTERDAY-$TODAY
/usr/sbin/squid -k rotate
exit 0

– save by pressing :wq and Enter –

Weekly Report :

root@server:~# vim /usr/sbin/sarg-weekly-report

– By pressing the letter i, Please insert : –

TODAY=$(date +%d/%m/%Y)
YESTERDAY=$(date –date “1 week ago” +%d/%m/%Y)
sarg /var/log/squid/access.log -o /var/www/squid-reports/weekly -z -d $YESTERDAY-$TODAY
/usr/sbin/squid -k rotate
exit 0

– save by pressing :wq and Enter –

Monthly Report :

root@server:~# vim /usr/sbin/sarg-monthly-report

– By pressing the letter I , Please insert : –

TODAY=$(date +%d/%m/%Y)
YESTERDAY=$(date –date “1 month ago” +%d/%m/%Y)
sarg /var/log/squid/access.log -o /var/www/squid-reports/monthly -z -d $YESTERDAY-$TODAY
/usr/sbin/squid -k rotate
exit 0

– save by pressing :wq and Enter –

The next step is to change the file permissions on the above report :

root@server:~# chmod 755 /usr/sbin/sarg-daily-report
root@server:~# chmod 755 /usr/sbin/sarg-weekly-report
root@server:~# chmod 755 /usr/sbin/sarg-monthly-report

To run it manually sarg report please do the following:

root@server:~# /usr/sbin/sarg-daily-report
root@server:~# /usr/sbin/sarg-weekly-report
root@server:~# /usr/sbin/sarg-monthly-report

This will produce reports in accordance with the existing output in each of the syntax, and to run sarg automatically we can add the command sarg we have made earlier in the /etc/crontab :

root@server:~# crontab -e

– By pressing the letter i, Please insert : –

00 00 * * * /usr/sbin/sarg-daily-report
00 01 * * 1 /usr/sbin/sarg-weekly-report
03 02 1 * * /usr/sbin/sarg-monthly-report

– save by pressing :wq and Enter –

Then we restart the crontab with the command :

root@server:~# /etc/init.d/cron restart

Finally finished already SARG installation on ubuntu and to see the results please go to the :

  • http://ip_address_server/squid-reports/daily to view the log daily sarg
  • http://ip_address_server/squid-reports/weekly to view the log sarg weekly
  • http://ip_address_serversquid-reports/monthly to see the sarg log monthly

Publish on October 17th, 2011 under Ubuntu by udiniq | 6 Comments »

6 Komentar to “Install SARG (Squid Analysis Report Generator) at Ubuntu”

  1. Jason Says:

    Worked great except for this line in the report files, YESTERDAY=$(date –date “1 week ago” +%d/%m/%Y). This through errors for me it didn’t understand the –date “1 week ago” part so I took it out and it works great.

    Thanks alot for the tutorial.

  2. udiniq Says:

    The script should run well, because I’ve applied it to several customer-owned servers

  3. Randre` Says:

    Thank you very much! This articled helped me get sarg working with zero problems.

  4. Buy Fan Says:

    Trackback Link…

    [...]Here are some of the sites we recommend for our visitors[...]…

  5. SharipovaM Says:

    Jason, for fixing bug in the script you need to put –date instead of -date

    YESTERDAY=$(date –date “1 week ago” +%d/%m/%Y)

    In order to prevent mistakes tt’s better to type the script by hand rather then to copy and paste.
    Thanx a lot for the author!!!

  6. udiniq Says:

    OK Thanks, I also do not understand why in the view – (double strip) can be transformed into – (one strip), and it was not copy and paste, because the wp-admin article is correct.

Berikan Komentar Anda

= 1+6 (Wajib dijumlahkan)