Find the answer to your Linux question:
Results 1 to 2 of 2
I have apache logs that I'm trying to create some metrics with. I've stripped the files down to number of request per second. Example: 03:04:01 3 (hour:minute:second #of requests) 03:04:03 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Feb 2010
    Posts
    1

    Inserting Missing Timestamps


    I have apache logs that I'm trying to create some metrics with. I've stripped the files down to number of request per second. Example:

    03:04:01 3 (hour:minute:second #of requests)
    03:04:03 2
    03:04:04 1
    03:04:05 1
    03:04:07 2

    My problem is that not every second has a request so of course no log entry for that given second. I need to insert each missing second and a zero for the request.

    I'm really not sure how to go about doing that. I guess create a loop that would create a time stamp for each second of the 24 hour period (84600 seconds) and then grep the file for that second. If the second does not exist then cat the line to the file, and eventually sort the file. Seems like that would take up a pretty big chunk of time.

    Creating a loop to generate each time stamp is beyond my scripting skills and anything I've tried has come up way short.

    Anyone have a solution using BASH, SH, PERL...

    Thanks for any suggestions.

  2. #2
    Linux User
    Join Date
    Mar 2008
    Posts
    287

    Inserting Missing Timestamps

    I tried to create a solution for you in bash and because I always forget that time is never easy to conquer I gave up on it.
    BUT, I think an easier solution is as follows. Use vi/vim to create a second file of a complete time sequence with 0 for responses. Use "sort" to sort both files together on time (set key= start and end) but use -t to ignore ":". Now you have a file which has all zero responses filled in but with a duplicate time that has responses > 0. You can now contrive a means to remove the 0-valued time via manual or other means. Suggest making a duplicate of original file, make all responses zero then use that file to grep against the file with duplicates to remove the zero value. I think this approach will take less time than constructing a bash file.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •