Page MenuHomec4science

webstat.in
No OneTemporary

File Metadata

Created
Thu, Jul 11, 11:19

webstat.in

#!/bin/sh
## -*- mode: script; coding: utf-8; -*-
##
## This file is part of Invenio.
## Copyright (C) 2005, 2006, 2007, 2008, 2010, 2011 CERN.
##
## Invenio is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 2 of the
## License, or (at your option) any later version.
##
## Invenio is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Invenio; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
## fill config variables:
VERSION='0.1'
LISPIMAGEDIR=@prefix@/lib/lisp/invenio
CONFIGDIR=@prefix@/etc/webstat
CLISP=@CLISP@
CMUCL=@CMUCL@
SBCL=@SBCL@
LOGDIR=@prefix@/var/log
TMPDIR=@prefix@/var/tmp
INVENIOLOGFILE=${LOGDIR}/invenio.err
APACHELOGFILE=${LOGDIR}/apache.err
#Search string with format: '^>> 2010-07-02'
searchstringmonth="^\(>> \)*"`date +%Y-%m-`
searchstringday="$searchstringmonth"`date +%d`
numberoferrors=100
## usage helper function:
usage () {
echo "Usage:" $0 "[options] <httpd-log-file>"
echo "General options:"
echo " -e, --error-log Error log analyzer mode"
echo " -h, --help Print this help."
echo " -V, --version Print version information."
echo "Error log analyzer mode options:"
echo " Invenio error log options:"
echo " -is, --isplit Create splitted files for each error (of today)"
echo " -ir, --iranking Print error ranking of the last 500 errors in this month."
echo " -il N, --ilast-errors=N Print last N errors."
echo " -id N, --ierror-details=N Print details of a specific error. N is the position "
echo " of the error, starting from the end (1 is the last error)"
echo " Apache error log options:"
echo " -ar, --aranking Print error ranking."
echo "Description: print interesting usage stats from the Apache log file."
echo "Note: Please analyze only moderately-sized logs, e.g. for a day or a week."
}
errorLogMode(){
##INVENIO
## looking for splitted files?
if [ "$2" = "-is" ] || [ "$2" = "--isplit" ]; then
invenioSplit
fi
## looking for ranking info?
if [ "$2" = "-ir" ] || [ "$2" = "--iranking" ]; then
invenioErrorRanking
fi
## looking for last errors?
if [ "$2" = "-il" ]; then
invenioLastErrors $3
fi
if [ "${2:0:14}" = "--ilast-errors=" ]; then
invenioLastErrors "${2:15}"
fi
## looking for error details?
if [ "$2" = "-id" ]; then
invenioErrorDetails $3
fi
if [ "${2:0:17}" = "--ierror-details=" ]; then
invenioErrorDetails "${2:17:27}"
fi
#APACHE
## looking for ranking info?
if [ "$2" = "-ar" ] || [ "$2" = "--aranking" ]; then
apacheErrorRanking
fi
## do we have enough arguments?
if [ ! -n "$2" ]; then
echo "Error: Not enough arguments."
usage
exit 1
fi
}
invenioSplit() {
rm ${TMPDIR}/inverr*
errors=`grep -c "$searchstringmonth" $INVENIOLOGFILE`
count=$(($errors-$numberoferrors))
if [[ $count -le 0 ]];then
chars=$((`echo $errors | wc -c`-1))
csplit -f ${TMPDIR}/inverr -n $chars $INVENIOLOGFILE /"$searchstringmonth"/ {$(($errors-1))}
else
chars=$((`echo $numberoferrors | wc -c`-1))
csplit -f ${TMPDIR}/inverr -n $chars $INVENIOLOGFILE %"$searchstringmonth"% {"$count"} /"$searchstringmonth"/ {$(($numberoferrors-2))}
fi
}
invenioErrorRanking () {
head -1 -q ${TMPDIR}/inverr* | cut -d ' ' -f 5- | cut -d ':' -f 1 | sort | uniq -c -w 14 | sort -nr
}
invenioLastErrors() {
head -1 -q ${TMPDIR}/inverr* | tail -n $1
}
invenioErrorDetails() {
filename=`ls ${TMPDIR} | grep 'inverr' | tail -n $1 | head -1`
cat ${TMPDIR}/$filename
}
apacheErrorRanking(){
rm ${TMPDIR}/apacheerrors.err
tail -n 700 $APACHELOGFILE | uniq -w 56 | cut -d ] -f 3- >> ${TMPDIR}/apacheerrors.err
pythonerrors=`cut -d ] -f 3- ${TMPDIR}/apacheerrors.err | grep /usr/lib/python2.6/dist-packages/ | cut -d ' ' -f 3 | sed s/Warning:// | sort | uniq -c | sed s/'$'/'Warning'/`
exceptionkeyerrors=`cut -d ] -f 3- ${TMPDIR}/apacheerrors.err | grep -v /usr/lib/python2.6/dist-packages/ | egrep -o 'Exception KeyError' | sort | uniq -c`
errorsbyclient=`cut -d ] -f 1 ${TMPDIR}/apacheerrors.err | cut -d ' ' -f 3 | sort | egrep '([0-9]{1,3}\.){3}[0-9]{1,3}' | uniq -c | sort -n -r`
apperrors=`grep 'Application error' ${TMPDIR}/apacheerrors.err | wc -l`
filenotexisterrors=`grep 'File does not exist' ${TMPDIR}/apacheerrors.err | wc -l`
#from here on it formats and displays all the errors
echo "Python errors:"
ws=$((7-${#apperrors}))
while [ $ws -gt 0 ]
do
fapperrors=$fapperrors" "
ws=`expr $ws - 1`
done
fapperrors="$fapperrors$apperrors Application error"
echo -e "$pythonerrors\n$fapperrors" | sort -r
echo "Document errors:"
ws=$((7-${#filenotexisterrors}))
while [ $ws -gt 0 ]
do
ffilenotexisterrors=$ffilenotexisterrors" "
ws=`expr $ws - 1`
done
ffilenotexisterrors="$ffilenotexisterrors$filenotexisterrors File does not exist"
echo -e "$exceptionkeyerrors\n$ffilenotexisterrors" | sort -r
echo "Errors by client:"
echo "$errorsbyclient"
}
## looking for version number?
if [ "$1" = "-V" ] || [ "$1" = "--version" ]; then
echo $VERSION
exit 0
fi
## looking for help?
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
usage
exit 0
fi
## looking for error log analyzer mode?
if [ "$1" = "-e" ] || [ "$1" = "--error-log" ]; then
errorLogMode $*
exit 0
fi
## do we have enough arguments?
if [ ! -n "$1" ]; then
echo "Error: Not enough arguments."
usage
exit 1
fi
## are input files okay?
FILECFG=${CONFIGDIR}/webstat.cfg
FILELOG=$1
if [ ! -f $FILECFG ]; then
echo "Error: config file ${FILECFG} not found."
exit 1
fi
if [ ! -f $FILELOG ]; then
echo "Error: httpd log file ${FILELOG} not found."
exit 1
fi
## check which Common Lisp implementation to use?
if [ "$LISP" == "" ]; then
LISP=cmucl
if [ ! -s ${LISPIMAGEDIR}/webstat.$LISP.core ]; then
LISP=sbcl
if [ ! -s ${LISPIMAGEDIR}/webstat.$LISP.core ]; then
LISP=clisp
if [ ! -s ${LISPIMAGEDIR}/webstat.$LISP.mem ]; then
echo "Error: no suitable Lisp images found in ${LISPIMAGEDIR}."
exit 1
fi
fi
fi
fi
## okay, try to run the process:
if [ "$LISP" == "cmucl" ]; then
$CMUCL -core ${LISPIMAGEDIR}/webstat.$LISP.core -quiet -batch \
-eval "(progn (analyze-httpd-log-file \"$FILECFG\" \"$FILELOG\")(quit))"
elif [ "$LISP" == "sbcl" ]; then
$SBCL --noinform --core ${LISPIMAGEDIR}/webstat.$LISP.core \
--eval "(progn (analyze-httpd-log-file \"$FILECFG\" \"$FILELOG\")(quit))"
elif [ "$LISP" == "clisp" ]; then
$CLISP -q -M ${LISPIMAGEDIR}/webstat.$LISP.mem \
-x "(progn (analyze-httpd-log-file \"$FILECFG\" \"$FILELOG\")(quit))"
else
echo "Error: $LISP not supported. Please read README."
exit 1
fi

Event Timeline