timn
Joined: 20 Nov 2003 Posts: 184 Location: United States
|
Posted: Fri Aug 21, 2009 9:17 am Post subject: Script: Counting Apache Internal Server Errors (Code 500) |
|
|
This is pretty simple, but I thought I'd share.
My web dev group asked if there was a way to monitor the number of code 500 errors ("Internal Server Errors") on our Apache-based sites and alert them if we saw an unusually high number of server errors.
This was my first attempt at scripting this kind of stuff so if you see problems -- or a better, more efficient way to do this, I'm open to learning. The method I have works, but I make no claims beyond that.
The script takes 2 parameters:
LogPath - full path to Apache web access_log
MaxErrors - set result to 'Bad' when this number is exceeded
Script is:
Code: |
#!/bin/sh
if [ $# -ge 2 ]
then
cat $1 | grep '" 500 ' | awk 'END {load='NR'; if (load>'$2') {printf("ScriptRes:Bad:%d\n",load)} else {printf("ScriptRes:Ok:%d\n",load)}; exit}'
else
echo 'ScriptRes:Unknown:not enough parameters specified'
fi
|
I have tested this only on Red Hat:
Quote: | # uname -a
Linux 215717-web2.www.company.com 2.6.18-128.1.1.el5 #1 SMP Mon Jan 26 13:58:24 EST 2009 x86_64 x86_64 x86_64 GNU/Linux |
|
|