Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^2: Any easy way to do this?

by jb60606 (Novice)
on Sep 15, 2011 at 00:41 UTC ( #926037=note: print w/ replies, xml ) Need Help??


in reply to Re: Any easy way to do this?
in thread Any easy way to do this?

#!/usr/bin/perl # Description: Read SRLabs feed handler log file, search for and print + "pending queues" exceeding a given threshold within a given time-fra +me. # 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 timefra +me 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]; # con +vert 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]; # con +vert 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 opt +ion 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 (<LOGFILE>){ 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]; # c +onvert 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 Queu +e 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"; }

-------------------------------------------------------------------------------------------------------------------

Example log file output

2011-09-12 10:32:16.285 pmmd-ltc-fsrlabs02 13996,14019: (WALL, MDConnection.cpp:420) Received data on ConnectionOPRA-GRP41-44. Pending=0. Total Messages processed by ConnectionOPRA-GRP41-44=10570000 0 2011-09-12 10:32:16.499 pmmd-ltc-fsrlabs02 13996,14019: (WALL, MDConnection.cpp:420) Received data on ConnectionOPRA-GRP17-20. Pending=0. Total Messages processed by ConnectionOPRA-GRP17-20=12193000 0 2011-09-12 10:32:16.876 pmmd-ltc-fsrlabs02 13996,14019: (WALL, MDConnection.cpp:420) Received data on ConnectionOPRA-GRP33-36. Pending=0. Total Messages processed by ConnectionOPRA-GRP33-36=10667000 0 2011-09-12 10:32:16.935 pmmd-ltc-fsrlabs02 13996,14019: (WALL, MDConnection.cpp:420) Received data on ConnectionOPRA-GRP45-48. Pending=0. Total Messages processed by ConnectionOPRA-GRP45-48=98140000 2011-09-12 10:32:16.966 pmmd-ltc-fsrlabs02 13996,14019: (WALL, MDConnection.cpp:420) Received data on ConnectionOPRA-GRP5. Pending=0. Total Messages processed by ConnectionOPRA-GRP5=31930000 2011-09-12 10:32:17.073 pmmd-ltc-fsrlabs02 13996,14019: (WALL, MDConnection.cpp:420) Received data on ConnectionOPRA-GRP17-20. Pending=0. Total Messages processed by ConnectionOPRA-GRP17-20=12194000 0 2011-09-12 10:32:17.123 pmmd-ltc-fsrlabs02 13996,14019: (WALL, MDConnection.cpp:420) Received data on ConnectionOPRA-GRP29-32. Pending=0. Total Messages processed by ConnectionOPRA-GRP29-32=10861000 0 2011-09-12 10:32:17.172 pmmd-ltc-fsrlabs02 13996,14019: (WALL, MDConnection.cpp:420) Received data on ConnectionOPRA-GRP37-38. Pending=0. Total Messages processed by ConnectionOPRA-GRP37-38=63700000 2011-09-12 10:32:17.196 pmmd-ltc-fsrlabs02 13996,14019: (WALL, MDConnection.cpp:420) Received data on ConnectionOPRA-GRP9-12. Pending=0. Total Messages processed by ConnectionOPRA-GRP9-12=119390000 2011-09-12 10:32:17.236 pmmd-ltc-fsrlabs02 13996,14019: (WALL, MDConnection.cpp:420) Received data on ConnectionOPRA-GRP13-16. Pending=87. Total Messages processed by ConnectionOPRA-GRP13-16=1041100 00 2011-09-12 10:32:17.248 pmmd-ltc-fsrlabs02 13996,14019: (WALL, MDConnection.cpp:420) Received data on ConnectionOPRA-GRP39-40. Pending=6. Total Messages processed by ConnectionOPRA-GRP39-40=51620000 2011-09-12 10:32:17.301 pmmd-ltc-fsrlabs02 13996,14019: (WALL, MDConnection.cpp:420) Received data on ConnectionOPRA-GRP41-44. Pending=341. Total Messages processed by ConnectionOPRA-GRP41-44=105710 000 2011-09-12 10:32:17.330 pmmd-ltc-fsrlabs02 13996,14019: (WALL, MDConnection.cpp:420) Received data on ConnectionOPRA-GRP1-4. Pending=2. Total Messages processed by ConnectionOPRA-GRP1-4=93230000 2011-09-12 10:32:17.374 pmmd-ltc-fsrlabs02 13996,14019: (WALL, MDConnection.cpp:420) Received data on ConnectionOPRA-GRP7-8. Pending=0. Total Messages processed by ConnectionOPRA-GRP7-8=63680000 2011-09-12 10:32:17.390 pmmd-ltc-fsrlabs02 13996,14019: (WALL, MDConnection.cpp:420) Received data on ConnectionOPRA-GRP25-28. Pending=0. Total Messages processed by ConnectionOPRA-GRP25-28=10501000 0 2011-09-12 10:32:17.392 pmmd-ltc-fsrlabs02 13996,14019: (WALL, MDConnection.cpp:420) Received data on ConnectionOPRA-GRP21-24. Pending=2. Total Messages processed by ConnectionOPRA-GRP21-24=89610000 2011-09-12 10:32:17.418 pmmd-ltc-fsrlabs02 13996,14019: (WALL, MDConnection.cpp:420) Received data on ConnectionOPRA-GRP6. Pending=0. Total Messages processed by ConnectionOPRA-GRP6=26110000

-------------------------------------------------------------------------------------------------------------------

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

I did mean 2500, but forgot to change the earlier thresholds. I only put 2500 in, to make it known that the thresholds won't be static and are completely decided by the user


Comment on Re^2: Any easy way to do this?
Select or Download Code
Re^3: Any easy way to do this?
by jb60606 (Novice) on Sep 15, 2011 at 00:44 UTC
    pardon the sloppy code, and i'm sure that there are much easier ways to accomplish that script. Still learning and just needed to whip something up quickly.
Re^3: Any easy way to do this?
by Anonymous Monk on Sep 15, 2011 at 13:34 UTC
    Oops... that logfile excerpt needs to be in a code-tag, too. Can you please edit the post? We only need to see one or two of the lines.
Re^3: Any easy way to do this?
by sohk220 (Initiate) on Aug 06, 2012 at 19:53 UTC
    Hey jb, I'm new to perl and wanted to know if you can explain the variables for your script. Thanks AJ

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://926037]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (14)
As of 2014-07-22 11:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (110 votes), past polls