KS-Soft. Network Management Solutions
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister    ProfileProfile    Log inLog in 

Script: Counting Apache Internal Server Errors (Code 500)

 
Post new topic   Reply to topic    KS-Soft Forum Index -> Library
View previous topic :: View next topic  
Author Message
timn



Joined: 20 Nov 2003
Posts: 184
Location: United States

PostPosted: Fri Aug 21, 2009 9:17 am    Post subject: Script: Counting Apache Internal Server Errors (Code 500) Reply with quote

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
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    KS-Soft Forum Index -> Library All times are GMT - 6 Hours
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


Powered by phpBB © 2001, 2005 phpBB Group

KS-Soft Forum Index