×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Summary and average per minute

Summary and average per minute

Summary and average per minute

(OP)
Hello,

I am trying to find out the average response time per minute from a log file that contains the response time in milliseconds. I would like to pipe the results into Awk and end up with the summary. I am looking for the most effective way to do it. The desired result is one line per minute that aggregates the results and provides the average. This is what I have so far to get the data from the application logs but still missing the last piece.

CODE --> windows

grep ">> DisplayStream" %1 | gawk "{print $1,$2,$NF}" | sed -e "s/^/%2 /g" -e "s/,[0-9][0-9][0-9]//g" >> results\%2.%3.log 

my data looks like this.

APP01 2016-02-16 00:00:05 85
APP01 2016-02-16 00:00:19 101
APP01 2016-02-16 00:00:37 147
APP01 2016-02-16 00:00:40 140
APP01 2016-02-16 00:00:54 161
APP01 2016-02-16 00:00:58 93
APP01 2016-02-16 00:00:59 19
APP01 2016-02-16 00:01:04 77
APP01 2016-02-16 00:01:08 83
APP01 2016-02-16 00:01:09 102
APP01 2016-02-16 00:01:11 91
APP01 2016-02-16 00:01:29 79
APP01 2016-02-16 00:01:29 133
APP01 2016-02-16 00:01:36 198
APP01 2016-02-16 00:01:40 135
APP01 2016-02-16 00:01:41 125
APP01 2016-02-16 00:01:48 105
APP01 2016-02-16 00:01:50 76
APP01 2016-02-16 00:01:55 196
APP01 2016-02-16 00:02:14 65
APP01 2016-02-16 00:02:36 87
APP01 2016-02-16 00:02:40 103
APP01 2016-02-16 00:02:50 159
APP01 2016-02-16 00:02:50 32
APP01 2016-02-16 00:02:56 135
APP01 2016-02-16 00:03:05 73
APP01 2016-02-16 00:03:09 133
APP01 2016-02-16 00:03:11 105
APP01 2016-02-16 00:03:15 84
APP01 2016-02-16 00:03:15 155
APP01 2016-02-16 00:03:18 111
APP01 2016-02-16 00:03:30 145
APP01 2016-02-16 00:03:43 231
APP01 2016-02-16 00:03:57 132
APP01 2016-02-16 00:03:59 73

RE: Summary and average per minute

Time calculations are normally best done in perl due to its builtin libraries, but that is just my 2c...

RE: Summary and average per minute

(OP)
I had to do some adjustments to the data formatting, I got rid of the seconds in the time stamp, so it looks like

CODE -->

APP01 2016-02-16 00:03 111
APP01 2016-02-16 00:03 145
APP01 2016-02-16 00:03 231
APP01 2016-02-16 00:03 132
APP01 2016-02-16 00:03 73 

then I passed it to the Following AWK program to summarize it, this seemed to have worked.

CODE --> Awk

function showavg() {
  printf("%s,%s %s,%d\n", lasthost, lastdate, last, s *1.0 / n);
  s = 0.0 ; n=0 ; f=0
}

BEGIN { last = "x" ; s=0.0 ; n=0 ; f=1 }

last==$3 { s+= $4 ; n++
}

last!=$3 { if ( f != 1 ) {
                showavg()
        }
        s = $4
        n = 1
        f = 0
        last = $3
        lasthost = $1
        lastdate = $2
}

END  { if ( f != 1 ) { showavg() } } 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close