Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Parsing a specific section of a log file

by jethro (Monsignor)
on Mar 03, 2007 at 01:32 UTC ( [id://603003]=note: print w/replies, xml ) Need Help??


in reply to Parsing a specific section of a log file

My solution would involve the seek and tell functions to resume every five minutes where you left off the last time. And a small file where you would store file position from tell() and the results of the last 5 chunks of 5(!) minutes of logfile you scanned (lets call them subresults).

The result of a 30 minutes check would then be the logical AND of the last 6 subresults (five from the file and one from the last scan) for the success line combined with the logical AND of the last 6 subresults for the non-zero value.

Hope I made sense.

  • Comment on Re: Parsing a specific section of a log file

Replies are listed 'Best First'.
Re^2: Parsing a specific section of a log file
by vxp (Pilgrim) on Mar 03, 2007 at 21:45 UTC
    but the goal is to check every 5 minutes for 30 mins back :)

    so if for example now is 17:15 you want to read the file back to 16:45 and note if theres a string you are interested in

    and at 17:20 you are supposed to check back to the 16:50 timestamp and note if theres at least 1 string in that timeframe

    and if i understood you correctly (perhaps i didnt ? ) your solution would only "run" (the logical AND) every 30 mins

    and to further complicate matters, this script cant run as a daemon/process that continously runs :)

    this is a Hobbit (monitoring tool like BigBrother, Nagios, etc) check, and as such can only run when Hobbit execs it (each 5 mins in this case) :)

      No, my solution would make a logical AND every 5 minutes. I'll elaborate:

      At 17:20 your program would get called and would read in a small file (lets call it /tmp/last). In that file would be stored
      1) a file positon from tell
      2) two boolean values for the time slot 16:50 to 16:55 (note the difference to above)
      3) two boolean values for the time slot 16:55 to 17:00
      ...
      6) two boolean values for the time slot 17:10 to 17:15

      Now your program would open the logfile, seek to the file position from 1), read the logfile from there and calculate the two boolean values (is there a success line? is there a non-zero value ?). This would be the result for time slot 17:15 to 17:20

      Now the program can calculate the endresult for the half hour by ANDing the values from 2) to 6) and the newly calculated values.

      Finally the program overwrites /tmp/last and stores the following into it:
      1) the file position from tell
      2) two boolean values for the time slot 16:55 to 17:00
      2) two boolean values for the time slot 17:00 to 17:05
      ...
      6) the newly calculated boolean values for the time slot 17:15 to 17:20

      After 5 minutes your program gets called and does all of the above again. The temporary file is like a pipeline storing only the last 5 results, shifting out an old one and getting a new one.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (2)
As of 2024-04-26 02:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found