[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.1

Parse the log file to calculate the average time

Asked by wesly_chen in Perl Programming Language, Shell Scripting

Tags: Perl

Hi,

   I have a log file and I do
grep "doMatch\(\)" info.log | tail -5
with the output like
Case 1:
===================
2008-10-29 17:52:28,606 [INFO ] AM_thread -- END doMatch()
2008-10-29 17:56:28,288 [INFO ] AM_thread -- START doMatch()
2008-10-29 17:59:39,496 [INFO ] AM_thread -- END doMatch()
2008-10-29 18:03:39,582 [INFO ] AM_thread -- START doMatch()
2008-10-29 18:06:57,863 [INFO ] AM_thread -- END doMatch()
====================
or
Case 2:
----------
2008-10-29 17:59:39,496 [INFO ] AM_thread -- END doMatch()
2008-10-29 18:03:39,582 [INFO ] AM_thread -- START doMatch()
2008-10-29 18:06:57,863 [INFO ] AM_thread -- END doMatch()
========================
   I want to extract out the event start and end time and calculate the average time span for the event.
In case 1, there are two events,
 Event1 started at 2008-10-29 17:56:28,288 and ended at 2008-10-29 17:59:39,496. So this event spends 191.208 seconds.
 Event 2 started at 2008-10-29 18:03:39,582 and ended at 2008-10-29 18:06:57,863. So event 2 spends 198.281 seconds.

  For average of two events, it is ( 191.208 + 198.281 ) / 2 = 194.745 seconds

In case 2, there are one event,
 This event started at 2008-10-29 18:03:39,582 and ended at 2008-10-29 18:06:57,863. So event 2 spends 198.281 seconds.
 So the average time is  198.281 seconds

  I need the help to write a script to parse the log files and and calculate the average time in case 1 or case 2.
This script will
1. parse the output from "grep "doMatch\(\)" info.log | tail -5" and
  if there are 4 or 5 lines from the output, then calculate the average time with two events, (between START - END)
  if there are 3 or 2 lines from the output, then calculate the time difference between START - END
  if there are less than 2 lines, error out with message "There are less than two timestamp to calculate the average time"
2. convert those timestamp into ms format and calculate the difference and average time.
3. Print out the result.

The output of this script will sho
1. The end time of the last event, in this example, it is 2008-10-29 18:06:57,863
2. The average time, 194.745 (or 198.281) seconds in my example.
such as
-----------
Time calculated : 2008-10-29 18:06:57,863
Average time    : 194.745 seconds
-----------

    The challenge part is converting the time format (2008-10-29 18:06:57,863) into ms format then do the calculation.

    It is really appreciated that some experts can help me out on this.
[+][-]10/29/08 08:28 PM, ID: 22837844Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: Perl Programming Language, Shell Scripting
Tags: Perl
Sign Up Now!
Solution Provided By: Adam314
Participating Experts: 1
Solution Grade: A
 
[+][-]10/29/08 12:17 PM, ID: 22834583Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/29/08 12:34 PM, ID: 22834740Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/29/08 04:07 PM, ID: 22836732Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/29/08 05:09 PM, ID: 22837004Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/29/08 06:50 PM, ID: 22837518Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/29/08 08:04 PM, ID: 22837738Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091118-EE-VQP-93 / EE_QW_2_20070628