gulden has asked for the wisdom of the Perl Monks concerning the following question:
I need your help to find a fast algorithm to process log files, finding the pairs and then generate a new logfile joining the pairs information in a single entry.
I have to process log files that are generated per minute, so my processing time should be below a minute.
An example of the logfiles:
FILE_MINUTE_0.logFILE_MINUTE_1.log20090619 ID = 0 TIMESTAMP = 1244127600 COUNT_2 = 10
FILE_MINUTE_2.log20090619 ID = 0 TIMESTAMP = 1244127600 COUNT_1 = 10 20090619 ID = 1 TIMESTAMP = 1244127600 COUNT_1 = 10 20090619 ID = 1 TIMESTAMP = 1244127600 COUNT_2 = 10 20090619 ID = 2 TIMESTAMP = 1244127600 COUNT_1 = 10 20090619 ID = 3 TIMESTAMP = 1244127600 COUNT_2 = 10 20090619 ID = 4 TIMESTAMP = 1244127600 COUNT_1 = 10
20090619 ID = 4 TIMESTAMP = 1244127600 COUNT_2 = 10
I've to process the above files and generate a new one joining the entries with the same ID. This would be the final Log File after processing "FILE_MINUTE_1.log"
FINAL_FILE_1.log20090619 ID = 0 TIMESTAMP = 1244127600 TOTAL = COUNT_1 + COUNT_2 20090619 ID = 1 TIMESTAMP = 1244127600 TOTAL = COUNT_1 + COUNT_2 20090619 ID = 2 TIMESTAMP = 1244127600 TOTAL = COUNT_1 --> COUNT_2 does Not exist 20090619 ID = 4 TIMESTAMP = 1244127600 TOTAL = COUNT_1 + COUNT_2
From the above file the record with ID=3 doesn't appear since its a pair without the entry "COUNT_1"
My approaches:
1. Put the log entries into a temporary SQL table, and then generate the output based on a Query that joins the entries by ID.
2. Put All the log entries into HASH TABLE like this:
$hash = ( 'FILE_MINUTE_2' => { 1 => {ID=1, COUNT_1 = 10, COUNT_2 = 20}, 2 => {ID=2, COUNT_1 = 10, COUNT_2 = undef}, 3 => {ID=3, COUNT_1 = undef, COUNT_2 = 20}, 4 => {ID=4, COUNT_1 = 10, COUNT_2 = 20}, }, );
And after reading the LogFiles, then I just need to process the HASH TABLE in order to generate the output file.
Another considerations:
Any tip will be helpful. Tks
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Process Log Files - Join Log entry pairs
by Utilitarian (Vicar) on Jun 17, 2009 at 12:52 UTC | |
by Transient (Hermit) on Jun 17, 2009 at 14:24 UTC | |
Re: Process Log Files - Join Log entry pairs
by gulden (Monk) on Jun 23, 2009 at 21:47 UTC |