The OpenNET Project / Index page

[ новости /+++ | форум | теги | ]



Индекс форумов
Составление сообщения

Исходное сообщение
"SARG отчет за по каждому дню"
Отправлено aon78, 06-Мрт-06 10:57 
>>Помогите разобраться
>>как правильно создать отчет за каждый день
>>#! /bin/sh
>>DAY=$(date+%d/%m/%Y)
>
>>/usr/bin/sarg -d $DAY
>
>>очеты после срабатывания создаються за весь период работы Squida
>
>Я у себя на сервере кручу по крону (в конце приведено) скрипт,
>приведенный ниже. Это исправленный скрипт, который был найден на сайте сквида
>или сарга, уже точно и не помню. Исправления касаются генерации недельных
>отчетов. Ротация логов происходит в этом же скрипте.
>
>
>#!/usr/local/bin/bash
># SARG - Daily/Weekly/Monthly Squid usage reports creation tool
># Written by Ugo Viti <ugo.viti@initzero.it>
>
># Thanks for enanchements to:
># - martijn
># - Stas Degteff https://sourceforge.net/users/stas_degteff/
>
>VER=20050202
>
>## What is this?
># sarg-reports (this file) is a simple bash script written 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 access 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
># (SQUID) The squid executable location
>#      (CONFIG) The sarg main configuration file
>location
>#      (LOGDIR) Location where logfiles lies
>#(ROTATEDLOGFILE) Name of file where will be current log after log rotation
>
>#     (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)
>
>#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
>## Italian Language
>#       SARG=/usr/bin/sarg
>#     CONFIG=/etc/sarg/sarg.conf
>#    HTMLOUT=/var/www/html/admin/log/proxy
>#  PAGETITLE="Statistiche Proxy di $(hostname)"
>#    LOGOIMG=http://www.initzero.it/images/initzero-logo.jpg
>#   LOGOLINK=http://www.initzero.it
>#      DAILY=Giornaliero
>#     WEEKLY=Settimanale
>#    MONTHLY=Mensile
>#EXCLUDELOG1="SARG: Nessun records trovato."
>#EXCLUDELOG2="SARG: Fine"
>#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
>
>
>#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
>## Russian Language
>    SARG="/usr/local/bin/sarg"
>    SQUID="/usr/local/sbin/squid"
>    CONFIG=/usr/local/etc/sarg/sarg.conf
>    LOGDIR=/var/log/squid
>    ROTATEDLOGFILE=access.log.0
>    HTMLOUT=/usr/local/www/internal/sarg-reports
>    PAGETITLE="пФЮЕФ РП ЙУРПМШЪПЧБОЙА ФТБЖЖЙЛБ Squid"   #
>russian koi8-r
>    LOGOIMG=http://litek.ru/images/logotop.gif
>    LOGOLINK=http://litek.ru
>    DAILY="еЦЕДОЕЧОЩК ПФЮЕФ"     # russian
>koi8-r
>    WEEKLY="пФЮЕФ ЪБ ОЕДЕМА"     #
>russian koi8-r
>    MONTHLY="пФЮЕФ ЪБ НЕУСГ"     #
>russian koi8-r
>EXCLUDELOG1="SARG: Records in file:"
>#EXCLUDELOG2="SARG: ïÔÞÅÔ ÕÓÐÅÛÎÏ ÓÇÅÎÅÒÉÒÏ×ÁÎ ×" # sarg.conf: language Russian_koi8
>EXCLUDELOG2=""
>#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
>
>
>######################################################################
>## The configuration is end, so don't touch anything bellow
>
># TEMP Files
>TMPFILE=/tmp/sarg-reports.$RANDOM
> ERRORS="${TMPFILE}.errors"
>
># Date Calc
>MANUALDATE=$2
>case "$(uname)" in
>"FreeBSD")
>         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)
>   ;;
>#"OpenBSD")
>#         TODAY=$(date +%d/%m/%Y)
>#     YESTERDAY=$(date -r $((`date +%s` - 86400 ))
>+%d/%m/%Y)
>#       WEEKAGO=$(date -r $((`date +%s` -
>604800)) +%d/%m/%Y)
>#      MONTHAGO=$(perl -e '@t=localtime(time); $y=$t[4]==0?$t[5]+1899:$t[5]+1900; $m=$t[4]==0?12:$t[4]; print "1/$m/$y-",$m==2?$y%4>0?28:29:$m==4||$m==6||$m==9||$m==11?30:31 ,"/$m/$y\n";')
>#   ;;
>*)
>         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)
>   ;;
>esac
>
># 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 "\
>  <html>\n\
>  <head>\n\
>  <title>$PAGETITLE</title>\n\
>  <META http-equiv=Content-Type content=\"text/html; charset=koi8-r\">\n\
>  </head>\n\
>  <body>\n\
>  <div align=center>\n\
>    <table border=0 cellspacing=6 cellpadding=7>\n\
>      <tr>\n\
>        <th align=center nowrap><b><font face=Arial size=4 color=green>$PAGETITLE</font></b></th>\n\
>      </tr>\n\
>      <tr>\n\
>        <td align=center bgcolor=beige><font face=Arial size=3><a href=daily/>$DAILY</a></font></td>\n\
>      </tr>\n\
>      <tr>\n\
>        <td align=center bgcolor=beige><font face=Arial size=3><a href=weekly/>$WEEKLY</a></font></td>\n\
>      </tr>\n\
>      <tr>\n\
>        <td align=center bgcolor=beige><font face=Arial size=3><a href=monthly/>$MONTHLY</a></font></td>\n\
>      </tr>\n\
>    </table>\n\
>  </div>\n\
>  </body>\n\
>  </html>" > $HTMLOUT/index.html
>}
>
>reports_autorm () {
>  BAKLIST="${TMPFILE}.BAKLIST"
>  BAKLISTTOLEAVELIST="${BAKLIST}.TOLEAVE.LIST"
>  BAKLISTTOLEAVEFIND="${BAKLIST}.TOLEAVE.FIND"
>  touch $BAKLIST $BAKLISTTOLEAVELIST $BAKLISTTOLEAVEFIND
>
>  cd $DESTINATION
>
>  find -name "*$BAKNAME*" -maxdepth 1 | sed -e 's/.\///' | grep -wv "." | sort 1> $BAKLIST
>
>  let TOLEAVEDAYS="$DAYBAK+1"
>
>  if [ $TOLEAVEDAYS -ge "0" ]
>    then
>      cat $BAKLIST | tail -n $TOLEAVEDAYS > $BAKLISTTOLEAVELIST
>      for BAK in $(cat $BAKLISTTOLEAVELIST)
>        do
>          echo "! -name $BAK" >> $BAKLISTTOLEAVEFIND
>        done
>  fi
>
>  CURRENTH=$(date +%H)
>  CURRENTM=$(date +%M)
>  if [ ${CURRENTH:0:1} == 0 ]
>  then
>    CURRENTH=${CURRENTH:1:1}
>  fi
>  if [ ${CURRENTM:0:1} == 0 ]
>    then
>      CURRENTM=${CURRENTM:1:1}
>  fi
>  let MINUTES="((($DAYBAK*24)+$CURRENTH)*60)+$CURRENTM+1"
>
>  # Purging old backups, only if backup return "OK" status
>
>  find $DESTINATION -name "*$BAKNAME*" $(cat $BAKLISTTOLEAVEFIND) -maxdepth 1 -mmin +$MINUTES
>-exec rm -rf {} \;
>  #find $DESTINATION $(cat $BAKLISTTOLEAVEFIND) -maxdepth 1 -mmin +$MINUTES -exec rm
>-rf {} \;
>}
>
># Functions
>exclude_from_log ()
>{
>  cat $ERRORS | grep -v "$EXCLUDELOG1" | grep -v "$EXCLUDELOG2"
>
>  rm -f $TMPFILE*
>}
>
>manual ()
>{
>  DAILYOUT=$HTMLOUT/$DAILY
>  mkdir -p $DAILYOUT
>  create_index_html
>  if [ -z "$MANUALDATE" ]
>    then
>      echo "No date given, please specify
>a valid date (DD/MM/YYYY)"
>    else
>      $SARG -f $CONFIG -d $MANUALDATE -o
>$DAILYOUT
>  fi
>}
>
>today ()
>{
>  DAILYOUT=$HTMLOUT/daily
>  mkdir -p $DAILYOUT
>  create_index_html
>  $SARG -f $CONFIG -d $TODAY -o $DAILYOUT >$ERRORS 2>&1
>  exclude_from_log
>}
>
>daily ()
>{
>  DAILYOUT=$HTMLOUT/daily
>  mkdir -p $DAILYOUT
>  create_index_html
>  #Squid must be running !!
>  $SQUID -k rotate
>#  [ ! -e $LOGDIR/$ROTATEDLOGFILE ] &&
>  touch $LOGDIR/$ROTATEDLOGFILE
>  sleep 120
># $SARG -l $LOGDIR/$ROTATEDLOGFILE -f $CONFIG -d $YESTERDAY -o $DAILYOUT >$ERRORS 2>&1
>  $SARG -l $LOGDIR/$ROTATEDLOGFILE -f $CONFIG -o $DAILYOUT >$ERRORS 2>&1    
>  cat $LOGDIR/$ROTATEDLOGFILE>>$LOGDIR/weekly.log
>  cat $LOGDIR/$ROTATEDLOGFILE>>$LOGDIR/monthly.log
>  rm  $LOGDIR/$ROTATEDLOGFILE
>  exclude_from_log
>}
>
>weekly ()
>{
>  WEEKLYOUT=$HTMLOUT/weekly
>  mkdir -p $WEEKLYOUT
>  create_index_html
># $SARG -l $LOGDIR/weekly.log -f $CONFIG -d $WEEKAGO-$YESTERDAY -o $WEEKLYOUT >$ERRORS 2>&1
>  $SARG -l $LOGDIR/weekly.log -f $CONFIG -o $WEEKLYOUT >$ERRORS 2>&1    
>  rm $LOGDIR/weekly.log
>  exclude_from_log
>}
>
>monthly ()
>{
>  MONTHLYOUT=$HTMLOUT/monthly
>  mkdir -p $MONTHLYOUT
>  create_index_html
># $SARG -l $LOGDIR/monthly.log -f $CONFIG -d $MONTHAGO -o $MONTHLYOUT >$ERRORS 2>&1
>  $SARG -l $LOGDIR/monthly.log -f $CONFIG -o $MONTHLYOUT >$ERRORS 2>&1
>  #    Rotate monthly log
>  [ -e $LOGDIR/monthly.10.gz ] && rm $LOGDIR/monthly.10.gz
>  for num in 9 8 7 6 5 4 3
>2 1 0;
>  do
>     nextnum=$(($num+1))
>     [ -e $LOGDIR/monthly.$num.gz ] && mv $LOGDIR/monthly.$num.gz
>$LOGDIR/monthly.$nextnum.gz
>  done
>  mv    $LOGDIR/monthly.log $LOGDIR/monthly.0
>  gzip  $LOGDIR/monthly.0
>  exclude_from_log
>}
>
>case $1 in
>    manual)
>        manual
>        ;;
>    today)
>        today
>        ;;
>    daily)
>        daily
>        ;;
>    weekly)
>        weekly
>        ;;
>    monthly)
>        monthly
>        ;;
>     *)
>        echo "SARG - Daily
>/ Weekly / Monthly - Squid proxy usage reports creation tool"
>
>        echo "Written by Ugo Viti <ugo.viti@initzero.it>"
>        echo "Version: $VER"
>        echo
>        echo "Usage: $0 [OPTIONS]"
>
>        echo
>        echo "Allowed options:"
>        echo "  
> manual,  Create Manual report"
>        echo "  
>  today,  Create Today report"
>        echo "  
>  daily,  Create Daily report"
>        echo "  
> weekly,  Create Weekly report"
>        echo "  
> montly,  Create Monthly report"
>        exit 0
>esac
>
>
>## HISTORY:
># 20050502 - Stas Degteff added support for non latin Charset and
>added support for OpenBSD
># 20030826 - FreeBSD support (thanks to martijn to let me coding
>on your FreeBSD server :-))
># 20030715 - Some cleanups
># 20030623 - Manual report creation
># 20030620 - Main Index creation
># 20030619 - Solved 'sort' bug on Red Hat 9 systems
># 20030618 - First Version
>
>
>## TODO:
># - Smarty weekly recognition...
>#   Like "begin of last week to end of last
>week",
>#   doesn't like this script do: "7 days ago to
>yesterday"
># - Monthly recognition isn't so elegant (is very ugly, i know)
>
># - Suggestions are welcome :-)
># - If you Rotate the squid logs before sarg-reports will run,
>
>#   it will not create any html reports
>#   (TIPS: Rotate the logs after sarg-reports)
>
>
>
>
>
>
>Использование:
>
>0       0    
>  *       *  
>     *      
> root    /usr/local/etc/sarg-scripts/sarg-reports daily
>15      0      
> *       *  
>    1      
>root    /usr/local/etc/sarg-scripts/sarg-reports weekly
>20      1      
> 1       *  
>    *      
>root    /usr/local/etc/sarg-scripts/sarg-reports monthly
>
>
>Если тебе хочется создавать отчеты за каждый день, то тебе поможет мой
>скрипт.
>
>
>Формулировка "как правильно создать отчет за каждый день" соответствует полученному результату "очеты
>после срабатывания создаються за весь период работы Squid-a". Если тебе хочется
>создать отчеты за каждый день - то используя твой скрипт у
>тебя это неплохо получается.
>
>
>
>Борец за грамотность )

Спасибо! Все получилось)

 

Ваше сообщение
Имя*:
EMail:
Для отправки новых сообщений в текущей нити на email укажите знак ! перед адресом, например, !user@host.ru (!! - не показывать email).
Более тонкая настройка отправки ответов производится в профиле зарегистрированного участника форума.
Заголовок*:
Сообщение*:
  Введите код, изображенный на картинке: КОД
 
При общении не допускается: неуважительное отношение к собеседнику, хамство, унизительное обращение, ненормативная лексика, переход на личности, агрессивное поведение, обесценивание собеседника, провоцирование флейма голословными и заведомо ложными заявлениями. Не отвечайте на сообщения, явно нарушающие правила - удаляются не только сами нарушения, но и все ответы на них. Лог модерирования.



Партнёры:
PostgresPro
Inferno Solutions
Hosting by Hoster.ru
Хостинг:

Закладки на сайте
Проследить за страницей
Created 1996-2024 by Maxim Chirkov
Добавить, Поддержать, Вебмастеру