Tips and tricks

Measure traffic from apache2 access.log

This command show current traffic today:
grep $(date ‘+%d/%b’) /var/log/apache2/access.log | awk ‘{ s += $10 } END { print s/1024/1024/ “MB”}’

This command lets ju choose which date you want to check traffic:
grep “day/month” /var/log/apache2/access.log | awk ‘{ s += $10 } END { print “Total “, s/1024/1024 ” MB”}’

The first thing that happends is to grep the current date from folder where the logs are stored. I use awk to add the result from column 10 to variable s. Output is displayed in bytes so we have to divide to get it more easy to read. If you have much traffic then divide again.