Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Summary and average per minute

Status
Not open for further replies.

OneArk

Technical User
Jul 25, 2008
12
CA
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:
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

 
Time calculations are normally best done in perl due to its builtin libraries, but that is just my 2c...
 
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:
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() } }
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top