I’ve been often in a situation where I needed to break down the server access log to visits per hour, for example to see if I had an hourly load increase.

Here’s a short code block which you can paste into the command line, just replace the /var/log/apache/access.log in the snippet to full path of the log that you wish to analyze, and also adjust the date (leave it in that format). If the logrotate daemon has already gzipped it, you can use zgrep instead of grep.

This should work out of the box both with Nginx and Apache.

grep "28/Aug" /var/log/apache/access.log | cut -d[ -f2 | cut -d] -f1 | awk -F: '{print $2":00"}' | sort -n | uniq -c

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.