Friday, November 23, 2012

Watch realtime HTTP requests per second

I've recently wanted to know how many requests per second where I having on a server. The server is using nginx as server and this is the way I found:

watch -n 1 'a="$(date +%d/%b/%Y:%H:%M:$(($(date +%S)-1)))";grep -c "$a" access.log'
I decrease the seconds in 1 unit as the current second could not be finished when the check is done (yes, it will fail on second 0 but... we have 59 seconds more!). You'll have to change the path to your access log file. You'll probably have to change the format of the date for other formats of access.log. Anybody knows a better way?


  1. I found a much better way to monitor the requests per second: apachetop. I am not sure if it also works for nginx.

  2. I use nginx status module on our environment as it's our load balancer. And I just want to add a one liner to gather info on spesific URLs with unique hits option. (not real time unless you add some date info regarding to log format)

    cat access.log|grep -i 'spesific_url_keyword'|awk '{print "requests from " $1}' | sort | uniq -c | wc -l

    BTW I know cat is not a good idea on a live log :)