#!/usr/bin/perl # Description: Read SRLabs feed handler log file, search for and print "pending queues" exceeding a given threshold within a given time-frame. # Usage: Run script without command line arguments for usage details use strict; my $hostname = `hostname -s`; $hostname =~ s/^\s*(\S*(?:\s+\S+)*)\s*$/$1/; my $total; # variable to be used for queue total for the given timeframe my $count = 0; # Check usage. Exit if incorrect, then display usage details my $numArgs = $#ARGV + 1; if (($numArgs <= 3) || ($numArgs > 5)) { print "\nusage:\n"; print usage(); exit 1; } else { # Get command line arguments, convert time to seconds my $logFile = $ARGV[0]; my $sTime= $ARGV[1]; my @sTime=split(/:/,$sTime); # split start time my $sSecs=$sTime[0] * 3600 + $sTime[1] * 60 + $sTime[2]; # convert start-time to seconds my $eTime = $ARGV[2]; my @eTime=split(/:/,$eTime); # split end time my $eSecs=$eTime[0] * 3600 + $eTime[1] * 60 + $eTime[2]; # convert stop-time to seconds my $tHold = $ARGV[3]; my $date = $ARGV[4]; # Get today's date which will be used as the default. Will add option to enter date, manually, soon my($day, $month, $year) = (localtime)[3,4,5]; $month = sprintf '%02d', $month+1; $day = sprintf '%02d', $day; $year = $year+1900; #my $ymd = "$year-$month-$day"; my $ymd = "2011-09-12"; open LOGFILE, "<", "$logFile" or die $!; while (){ my $line=$_; chomp; my @data=split(/ /,$line); # split the line up unless (($data[10] =~ m/Pending=/)) { next; } # skip elements we don't want my $lineInfo = $data[9]; $lineInfo =~ s/[Connection\[\].]//g; $data[10] =~ s/[A-Za-z=.]//g; # delete "Pending", "=" and "." $data[1] =~ s/\..*//g; # delete the millisecond element of the (current)cTime var my @cTime=split(/:/,$data[1]); # split the current time my $curSecs=$cTime[0] * 3600 + $cTime[1] * 60 + $cTime[2]; # convert current-time to seconds if (($data[0] eq $ymd) && ($data[10] >= $tHold) && ($curSecs >= $sSecs) && ($curSecs <= $eSecs)) { $count+1; $total += $data[10]; $count++; } else { next; } } print "$hostname,$ymd,$sTime-$eTime,$tHold,$count,$total\n"; print "\n$hostname ($ymd)\n"; print "$count pending queues meet or exceed $tHold\n"; print "Aggregate ($sTime to $eTime): $total\n\n"; # print the Queue for the timeframe } close LOGFILE; sub usage { print "\n\./readLog.pl [log-file] [start-time] [end-time] [threshold]\n\n"; print " log-file Log file name\n"; print " start-time Start time as HH:MM [e.g. \"06:00\"]\n"; print " end-time End time as HH:MM [e.g. \"13:15\"]\n"; print " max-pending Pending queue threshold [e.g. \"1000\"]\n\n"; } #### hostname,2011-09-14,8:30-15:00,5000,492,3704405 hostname (2011-09-14) 492 pending queues meet or exceed 5000 Aggregate (8:30 to 15:00): 3704405