Monday, July 11, 2016

Analyse Apache Access Log to view traffic


To view requests per day
awk '{print $4}' access_log | cut -d: -f1 | uniq -c

To view requests per hour
grep "12/Jul/2016" access_log | cut -d[ -f2 | cut -d] -f1 | awk -F: '{print $2":00"}' | sort -n | uniq -c


To view requests per minute
grep "12/Jul/2016:11" access_log | cut -d[ -f2 | cut -d] -f1 | awk -F: '{print $2":"$3}' | sort -nk1 -nk2 | uniq -c | awk '{ if ($1 > 10) print $0}'

If your logs are gzip'ed by logrotate, prefix another command to the above commands 
zcat /site/mysite.com/logs/access.log.gz | awk '{print $4}' | cut -d: -f1 | uniq -c

No comments:

Post a Comment