Create a script called log_monitor.sh:
#!/usr/bin/perl -w
use strict;
my $cachefile="/var/cache/lastpos-apache2-scan4maxclntOrSigKill";
my $logfile="/var/log/httpd/error_log";
my $searchstr=" 500 ";
my $lastpos=0;
if (-f $cachefile) {
open FH,"<".$cachefile;
$lastpos=<FH>;
close FH;
};
my $newpos=(stat $logfile)[7];
open FH,"<".$logfile;
seek FH,$lastpos,0;
while (<FH>) {
print if m/$searchstr/i;
};
close FH;
open FH,">".$cachefile;
print FH $newpos;
close FH;
modify $searchstr as needed. note the spaces around "500", since you don't want to match errors which contain a 404 on a file that has "500" in its path or filename (among other places).
configure the script to run every X minutes via cron. the greater the value of X, the less emails you will get (only 1 email every X minutes for all the errors that match the strings you supply). the results of the cron job will get emailed to you automatically (if cron is setup properly)
#!/usr/bin/perl -w
use strict;
my $cachefile="/var/cache/lastpos-apache2-scan4maxclntOrSigKill";
my $logfile="/var/log/httpd/error_log";
my $searchstr=" 500 ";
my $lastpos=0;
if (-f $cachefile) {
open FH,"<".$cachefile;
$lastpos=<FH>;
close FH;
};
my $newpos=(stat $logfile)[7];
open FH,"<".$logfile;
seek FH,$lastpos,0;
while (<FH>) {
print if m/$searchstr/i;
};
close FH;
open FH,">".$cachefile;
print FH $newpos;
close FH;
modify $searchstr as needed. note the spaces around "500", since you don't want to match errors which contain a 404 on a file that has "500" in its path or filename (among other places).
configure the script to run every X minutes via cron. the greater the value of X, the less emails you will get (only 1 email every X minutes for all the errors that match the strings you supply). the results of the cron job will get emailed to you automatically (if cron is setup properly)
else
Second way
Use monitoring, try OpenNMS or Nagios which are opensource
No comments:
Post a Comment