• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

对Squid proxy Server的完全分析程序:sarg-2.0.2.tar.gz

发布: 2007-7-04 12:06 | 作者: admin | 来源:  网友评论 | 查看: 22次 | 进入软件测试论坛讨论

领测软件测试网

昨天在网上看到SARG这个软件,就download下来,装在我的代理服务器上,哇噻,功能真是很强大.上网的记录完全的展现在你的面前,你浏览过的网页,下载过的东东,你的访问量,流量.......很全呀,不过,我都害怕了,这么全,我的上网记录不是全都爆光了:)

安装:

sarg-2.0.2.tar.gz

#tar -zxvf sarg-2.0.2.tar.gz

#cd sarg-2.0.2

#./configure

#make;make install

#vi /usr/local/sarg/sarg.conf         #根据你的实际情况修改了

#vi /etc/cron.daily/sarg.daily            #包括/etc/cron.weekly/sarg.weekly,/etc/cron.monthly/sarg.monthly,这些就是你的Squid proxy Server的日报表,周报表,月报表呀,不过如果你的流量很大的话,就不要做日报表了,太大了,很浪费你的硬盘空间.

以下是几个英文的说明档:我的采用的是Example One,大家可以根据自己的需求修改

sarg默认的输出的目录/var/www/html/,所以要创建/var/www/html/daily,monthly,weekly三个目录,或手动执行上述shell命令,在IE中打开http://yourip/daily,出来了吧
大家可以这里看一下我的抓图

Example One:

sarg.cron
# Please edit the following lines to match your requirements
# Also edit sarg.* scripts if you want to customize reports folder
# To enable report generation put last 3 lines into your /etc/crontab
# file.

05 0 * * * root /usr/sbin/sarg.daily
15 0 * * 1 root /usr/sbin/sarg.weekly
30 1 1 * * root /usr/sbin/sarg.monthly

sarg.monthly
#!/bin/bash

#Get yesterday date
YESTERDAY=$(date --date "1 day ago" +%d/%m/%Y)

#Get 1 month ago date
MONTHAGO=$(date --date "1 month ago" +%d/%m/%Y)

/usr/sbin/sarg -o /var/www/html/squid/monthly -d $MONTHAGO-$YESTERDAY
# > /dev/null 2>&1

/usr/sbin/squid -k rotate

exit 0

sarg.daily
#!/bin/bash
 
#Get yesterday date
YESTERDAY=$(date --date "1 day ago" +%d/%m/%Y)
 
/usr/sbin/sarg -o /var/www/html/squid/daily -d $YESTERDAY > /dev/null 2>&1
 
exit 0

sarg.weekly
#!/bin/bash

#Generate Access.log for correct weekly reports
cat /var/log/squid/access.log.0 /var/log/squid/access.log > /var/log/squid/access.log.week

#Get yesterday date
YESTERDAY=$(date --date "1 days ago" +%d/%m/%Y)

#Get one week ago date
WEEKAGO=$(date --date "7 days ago" +%d/%m/%Y)

/usr/sbin/sarg -l /var/log/squid/access.log.week -o /var/www/html/squid/weekly -d $WEEKAGO-$YESTERDAY > /dev/null 2>&1

exit 0

Example Two:

#!/bin/sh
# SARG - Daily/Weekly/Monthly Squid usage reports creation tool
# Written by Ugo Viti <u.viti@i-synapse.it>
# Visit http://www.i-synapse.it (Italian Page)
VER=20040228

## What is this?
# sarg-reports (this file) is a simple bash script to automate
# the SARG (a powerful squid log analyzer) reports and log management.
# Sarg it self, provide to end user a generic interface to create
# reports based on squid log (begin of log to current date).
# sarg-reports (this script) is useful because it allow you to easly
# create and manage Daily, Weekly and Monthly reports.
# Try it, within 5 minutes you will be ready to rule :-)
# using sarg-reports is very easy, read the following 3 steps to know how

## Requirements
# a) An unix system with bash shell (like GNU/Linux, FreeBSD, etc...)
# b) Squid - http://www.squid-cache.org
# c) Sarg - http://web.onda.com.br/orso/sarg.html


##
## Installation guide and configuration parameters
##

# 1) Download Squid and Sarg, Install, Configure and Tune
#    they before continue reading

# 2) In root crontab (crontab -e) insert the following lines:
#    (the today report creation time depend mostly of your squid server
#    load average, tune it):
#
#    --- BEGIN ROOT CRONTAB ---
#    PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
#    00 08-18/1 * * * sarg-reports today
#    00 00 * * * sarg-reports daily
#    00 01 * * 1 sarg-reports weekly
#    30 02 1 * * sarg-reports monthly
#    --- END ROOT CRONTAB ---
#
#    REMEMBER: if you use logrotate, configure it to rotate the logs within MONTHLY basis,
#              AFTER sarg-reports created the monthly html report.

# 3) Customize the following variables:
#    (Please, configure accurately the sarg.conf file before)
#
#        (SARG) The sarg executable location
#      (CONFIG) The sarg main configuration file location
#     (HTMLOUT) Location where will be saved the reports
#   (PAGETITLE) The title of main index page
#     (LOGOIMG) Image logo to view in main index page
#    (LOGOLINK) HTTP web page link of logo
#       (DAILY) Word 'daily' translation, translate it to your language
#      (WEEKLY) Word 'weekly' translation, translate it to your language
#     (MONTHLY) Word 'monthly' translation, translate it to your language
# (EXCLUDELOG1) Exclude text from cron emails
#       +       (normally, sarg, during cron activity, if it don't find any valid records,
# (EXCLUDELOG2) it will output an error message (usually on 'today' reports).
#               I don't want to be warned by email about this, so, i wrote the 'text'
#               that will be never logged.
#               This is useful to receive email of real problems only (enjoy that)

       SARG=/usr/sbin/sarg
     CONFIG=/etc/sarg/sarg.conf
    HTMLOUT=/var/www/virtual/i-synapse.it/www/html/admin/log/proxy
  PAGETITLE="Statistiche Proxy Squid di $(hostname)"
    LOGOIMG=http://www.i-synapse.it/images/synapse-logo.jpg
   LOGOLINK=http://www.i-synapse.it
      DAILY=Giornaliero
     WEEKLY=Settimanale
    MONTHLY=Mensile
EXCLUDELOG1="SARG: Nessun records trovato."
EXCLUDELOG2="SARG: Fine"


######################################################################
## The configuration is end, so don't touch anything bellow

# TEMP Files
TMPFILE=/tmp/sarg-reports.$RANDOM
 ERRORS="$.errors"

# Date Calc
if [ "$(uname)" = "FreeBSD" ]
  then
    MANUALDATE=
         TODAY=$(date +%d/%m/%Y)
     YESTERDAY=$(date -v-1d +%d/%m/%Y)
       WEEKAGO=$(date -v-1w +%d/%m/%Y)
      MONTHAGO=$(date -v-1m +01/%m/%Y)-$(date -v-1m +31/%m/%Y)
  else
    MANUALDATE=
         TODAY=$(date --date "today" +%d/%m/%Y)
     YESTERDAY=$(date --date "1 day ago" +%d/%m/%Y)
       WEEKAGO=$(date --date "1 week ago" +%d/%m/%Y)
      MONTHAGO=$(date --date "1 month ago" +01/%m/%Y)-$(date --date "1 month ago" +31/%m/%Y)
fi

# Fix for Red Hat 9 systems and coreutils prior to 5.0 version
export LC_ALL=C

# Main index.html creation
create_index_html ()
{
  echo -e "
  n
  n
  n
  n
  n
 

n
    .net/$LOGOIMG" border="0" / onclick="javascript:window.open(this.src);" style="CURSOR: pointer" onload="return imgzoom(this,550)">n
    n
      n
        n
      n
      n
        n
      n
      n
        n
      n
      n
        n
      n
   
$PAGETITLE
$DAILY
$WEEKLY
$MONTHLY
n
 

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网