View Single Post

  #2 (permalink)  
Old 05-06-2008
Kees Nuyt
 
Posts: n/a
Default Re: apache - how to monitor HTTP response codes

On Tue, 6 May 2008 08:49:23 -0700 (PDT), inetquestion
<inetquestion@hotmail.com> wrote:

>I am looking for a way to monitor the count of each HTTP response
>codes from apache reverse proxy servers. As a quick proof of concept
>I wrote the ksh script below to scan the HTTP response codes and show
>how many of each type occurred every hour. This code is very
>inefficient and would be much better if it were written in perl or
>something else that doesn't have to re-read the file so many
>times...
>
>Ultimately I would like the ability to poll the the count of each HTTP
>response code without having to parse access logs period. I checked
>into using /server-status, but this doesn't contain that type info...
>Is there something easy I am overlooking that wouldn't require parsing
>log files to get the information on a 10 minute basis?
>
>-Inet


I'm sure there is nothing you can do with Apache
configuration to solve this.

>#!/usr/bin/ksh
>
>FILE="$1"
>
>echo " 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20
>21 22 23"
>for CODE in 200 301 302 304 400 403 404 500; do
> print -n "$CODE "
> for HOUR in 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17
>18 19 20 21 22 23; do
> COUNT=`cat $FILE | grep "2008:$HOUR" | awk '{print $9}' | grep
>$CODE | wc -l`
> print -n "$(( COUNT )) "
> done
> echo
>done


Try something with:
awk 'print --select key fields here--' $1 \
| sort \
| uniq --count \
| awk '--some script to transpose results--'

Another possibility is to prepend every page with a
small php script that registers the hit in a database.

By the way,
cat $FILE | grep "2008:$HOUR"
is useless, you can directly grep the file:
grep "2008:$HOUR" $FILE

HTH
--
( Kees
)
c[_] If televison's a babysitter, the Internet
is a drunk librarian who won't shut up. (#301)