Take the 2-minute tour ×

I am trying to calculate the average requests per seconds for a specific period of time of my Apache logs.

I have been able to narrow the results down to the period I am interested in, as well as calculating the requests per second, but I am not able to calculate the average. Here is what I have so far:

paste "/var/log/apache2/access.log" "/var/log/apache2/access.log.1" | awk ' $4>"[10/Feb/2013:16:48:00" && $4<"[10/Feb/2013:17:15:00" {gsub(/\[/,"");print $4} ' | sort | uniq -c

Could anyone steer me in the right direction? I have mentioned sed or awk but I am happy to use something else.


share|improve this question
First of all: what is paste doing there? –  manatwork Feb 14 '13 at 10:21
I need to get the contents of all Apache log files and this seems to do the trick. What should I use instead? cat? –  Fred Feb 14 '13 at 10:24
Definitely not paste: pastebin.com/r0UA4eUt. Either cat or none: awk '{…}' /var/log/apache2/access.log /var/log/apache2/access.log.1. –  manatwork Feb 14 '13 at 10:28
What kind of awk you have? gawk has some handy time functions the others not have. –  manatwork Feb 14 '13 at 10:35
thanks, I have removed the paste bit. I have awk, although I could install gawk if needed. –  Fred Feb 14 '13 at 10:38

1 Answer 1

up vote 0 down vote accepted

Since you've already worked out how to get your requests per second, you need to decide what your 'average' represents; i.e. average requests over a 60 second period, or 5 minutes, or 15, or what not. Assuming it's over a 60 second, you could have your existing script append, every second, to a metrics log. Then have another script, every second, in a loop perform the following:

# tail -n 60 | awk '{total = total + $1}END{print total}' / 60 | bc -l

This will spit out the average requests, per second, over a 60 second period. To do it over 5 minutes:

# tail -n 300  | awk '{total = total + $1}END{print total}' / 300 | bc -l

If you need more clarification, feel free to comment.

share|improve this answer
Ideally I would have rathe have done it on the fly, but I guess I can output to an external file. Cheers –  Fred Feb 16 '13 at 2:08
You could simply pipe your existing awk output to what I wrote to a variable updated every second, then pipe it to my script. Am not home to write it now, will update it later though. –  Stephan Feb 16 '13 at 6:43

Your Answer


