Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Script log analyzer for error_log for apache
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
kamikaze04
Guru
Guru


Joined: 28 Mar 2004
Posts: 366
Location: Valencia-Spain

PostPosted: Mon Aug 29, 2005 2:51 pm    Post subject: Script log analyzer for error_log for apache Reply with quote

I've been searching long time for a log analyzer only specifically for apache. As i didn't found no program to do that i began searching for scripts.

I have found this one. I hope it will be usefull to anyone. At least for me isn't working 100% perfect but it does the trick.


Code:


#!/bin/sh

# weberrors - Scans through an Apache error_log file and reports the
#    most important errors, then lists additional entries.

temp="/tmp/$(basename $0).$$"

# The following three lines will need to be customized for your own
# installation for this script to work best.

htdocs="/var/www/localhost/htdocs"
myhome="/usr/home/taylor/"
cgibin="/var/www/localhost/cgi-bin/"

sedstr="s/^/  /g;s|$htdocs|[htdocs]  |;s|$myhome|[homedir] |;s|$cgibin|[cgi-bin] |"

screen="(File does not exist|Invalid error redirect|premature EOF|Premature end of
script|script not found)"

length=5                # entries per category to display
checkfor()
{
  grep "${2}:" "$1" | awk '{print $NF}' |\
    sort | uniq -c | sort -rn | head -$length | sed "$sedstr" > $temp

  if [ $(wc -l < $temp) -gt 0 ] ; then
    echo ""
    echo "$2 errors:"
    cat $temp
  fi
}

trap "/bin/rm -f $temp" 0

if [ "$1" = "-l" ] ; then
  length=$2; shift 2
fi

if [ $# -ne 1 -o ! -r "$1" ] ; then
  echo "Usage: $(basename $0) [-l len] error_log" >&2
  exit 1
fi

echo Input file $1 has $(wc -l < "$1") entries.

start="$(grep -E '\[.*:.*:.*\]' "$1" | head -n 1 | awk '{print $1" "$2" "$3" "$4" "$5
}')"
end="$(grep -E '\[.*:.*:.*\]' "$1" | tail -n 1 | awk '{print $1" "$2" "$3" "$4" "$5
}')"
echo -n "Entries from $start to $end"

echo ""

### Check for various common and well-known errors:

checkfor "$1" "File does not exist"
checkfor "$1" "Invalid error redirection directive"
checkfor "$1" "premature EOF"
checkfor "$1" "script not found or unable to stat"
checkfor "$1" "Premature end of script headers"

grep -vE "$screen" "$1" | grep "\[error\]" | grep "\[client " | \
  sed 's/\[error\]/\`/' | cut -d\` -f2 | cut -d\ -f4- | \
  sort | uniq -c | sort -rn | sed 's/^/ /' | head -n $length > $temp

if [ $(wc -l < $temp) -gt 0 ] ; then
  echo ""
  echo "Additional error messages in log file:"
  cat $temp
fi
echo ""
echo "And non-error messages occurring in the log file:"

grep -vE "$screen" "$1" | grep -v "\[error\]" | \
  sort | uniq -c | sort -rn | \
  sed 's/^/ /' | head -n $length

exit 0


All comments to this script are wellcome
_________________
Todo lo que quisiste saber sobre google en: www.noticiasgoogle.es
Back to top
View user's profile Send private message
step
Apprentice
Apprentice


Joined: 16 May 2002
Posts: 198

PostPosted: Mon Aug 29, 2005 2:58 pm    Post subject: Reply with quote

How about Analog ? 8O
(http://www.analog.cx)

Analog shows you the usage patterns on your web server. It's

* Ultra-fast
* Scalable
* Highly configurable
* Reports in 32 languages
* Works on any operating system
etc...
Back to top
View user's profile Send private message
kamikaze04
Guru
Guru


Joined: 28 Mar 2004
Posts: 366
Location: Valencia-Spain

PostPosted: Mon Aug 29, 2005 3:33 pm    Post subject: Reply with quote

I think that with analog i cannot have this output:

Code:

Input file error_log has 1040 entries.
Entries from [Sat Aug 23 18:10:21 2003] to [Sat Aug 30 17:23:38 2003]
File does not exist errors:
    24 [htdocs]  intuitive/coolweb/Graphics/Graphics/off.gif
    19 [htdocs]  intuitive/taylor/Graphics/biohazard.gif
    19 [homedir] public_html/tyu/tyu-toc.html
    14 [htdocs]  intuitive/Graphics/bottom-menu.gif
    12 [htdocs]  intuitive/tmp/rose-ceremony/spacer.gif

Invalid error redirection directive errors:
    23 index.html

script not found or unable to stat errors:
    55 [htdocs]  intuitive/coolweb/apps/env.cgi
     4 [htdocs]  intuitive/cgi-local/apps/env.cgi
     4 [cgi-bin] FormMail.pl
     3 [htdocs]  intuitive/origins/playgame.cgi

Additional error messages in log file:
     5 (35)Resource temporarily unavailable: couldn't spawn include command
     4 unknown parameter "src" to tag include in
/usr/local/etc/httpd/htdocs/intuitive/tmp/ECR0803b.shtml
     4 execution failure for parameter "cmd" to tag exec in file
/usr/local/etc/httpd/htdocs/intuitive/library/footer.shtml
     1 execution failure for parameter "cmd" to tag exec in file
/usr/local/etc/httpd/htdocs/intuitive/library/WindWillows.shtml

And non-error messages occurring in the log file:
    39 /usr/home/taylor/web/intuitive/library/header.cgi: Cannot fork: Resource
temporarily unavailable
    20 identify: Missing an image file name.
    17 sort: -: write error: Broken pipe
    16 /web/bin/lastmod: not found
    16 /web/bin/counter: not found

_________________
Todo lo que quisiste saber sobre google en: www.noticiasgoogle.es
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum