I have the next apache's log format: LogFormat %h %l %u %t \%r\ %>s %b %D \%{Referer}i\ \%{User-Agent}i\where's %D - The time taken to serve the request, in microseconds.I want to know how can I get an average response time for last 10 seconds. Somehow a script or something should calculate the number of requests for last 10 seconds and summarize the response time. The result should be: number_of_requests_for_last_10_seconds / sum_of_request_time_for_last_10_seconds.Is that possible to do with awk or something? ThanksUPDATELog's sample:93.182.72.47 - - [19/Aug/2014:02:24:19 -0700] GET /test/085 HTTP/1.1 200 1006 445 - Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Firefox/31.0119.232.112.148 - - [19/Aug/2014:02:24:19 -0700] GET /test/003 HTTP/1.1 200 3 84234 - Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.143 Safari/537.3685.244.38.232 - - [19/Aug/2014:02:24:19 -0700] GET /test/332 HTTP/1.1 200 3 75760 - Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36236.131.91.87 - - [19/Aug/2014:02:24:16 -0700] GET /test/006 HTTP/1.1 200 32 3640965 - python-requests/2.2.1 CPython/2.7.3 Linux/2.6.32-431.17.1.el6.x86_64112.241.72.130 - - [19/Aug/2014:02:24:19 -0700] GET /test/042 HTTP/1.1 200 50 1148668 - python-requests/2.2.1 CPython/2.6.6 Linux/2.6.32-431.20.3.el6.x86_64UPDATE2tailf /var/log/httpd/access_log | perl -MTime::Piece -lne '   BEGIN{$threshold = (localtime) - 10}   if (/\[(.*?)\] .*? \d+ \d+ (\d+)/) {     $d = Time::Piece->strptime($1, %d/%b/%Y:%H:%M:%S %z);print $d->datetime. .$threshold->datetime;     if ($d >= $threshold) {$t += $2; $n++}   }   END{print $t/$n if $n}' /var/log/httpd/access_log...2014-08-19T03:54:42 2014-08-19T03:54:272014-08-19T03:54:43 2014-08-19T03:54:272014-08-19T03:54:43 2014-08-19T03:54:272014-08-19T03:54:42 2014-08-19T03:54:272014-08-19T03:54:44 2014-08-19T03:54:272014-08-19T03:54:44 2014-08-19T03:54:272014-08-19T03:54:43 2014-08-19T03:54:272014-08-19T03:54:43 2014-08-19T03:54:272014-08-19T03:54:43 2014-08-19T03:54:272014-08-19T03:54:44 2014-08-19T03:54:272014-08-19T03:54:43 2014-08-19T03:54:272014-08-19T03:54:44 2014-08-19T03:54:272014-08-19T03:54:45 2014-08-19T03:54:272014-08-19T03:54:45 2014-08-19T03:54:272014-08-19T03:54:44 2014-08-19T03:54:272014-08-19T03:54:44 2014-08-19T03:54:272014-08-19T03:54:44 2014-08-19T03:54:272014-08-19T03:54:44 2014-08-19T03:54:272014-08-19T03:54:45 2014-08-19T03:54:272014-08-19T03:54:44 2014-08-19T03:54:272014-08-19T03:54:44 2014-08-19T03:54:272014-08-19T03:54:44 2014-08-19T03:54:272014-08-19T03:54:46 2014-08-19T03:54:27
Calculate Apache's response time for last 10 seconds
text processing
That's a typical job for perl:With Time::Piece 1.17 and above (perl 5.12 and above):perl -MTime::Piece -lne '   BEGIN{$threshold = (localtime) - 10}   if (/\[(.*?)\] .*? \d+ \d+ (\d+)/) {     $d = Time::Piece->strptime($1, %d/%b/%Y:%H:%M:%S %z);     if ($d >= $threshold) {$t += $2; $n++}   }   END{print $t/$n if $n}' your-file.logVersions of Time::Piece 1.15 and below didn't support %z, so, there, assuming the caller's timezone matches that of the log file, you could do instead:perl -MTime::Piece -lne '   BEGIN{$threshold = (localtime) - 10}   if (/\[([^]]*:\d+).*?.*? \d+ \d+ (\d+)/) {     $d = Time::Piece->strptime($1, %d/%b/%Y:%H:%M:%S);     if ($d->datetime ge $threshold->datetime) {$t += $2; $n++}   }   END{print $t/$n if $n}' your-file.log