Measure traffic from apache access log

Try this. I tested it on a local file but cannot tell if it works on all configurations/locales/...

cat apache.log | perl -e 'my $sum=0; while(<>) { my ($traffic) = m/\[.+\] ".+" \d+ (\d+)/; $sum += $traffic}; print "$sum\n"'

Update Jan 2017: Meanwhile I've learned some more Perl and that's how I'd do it today:

cat apache.log | perl -nE '/\[.+\] ".+" \d+ (\d+)/; $sum += $1; END {say $sum}'

For detailed log file monitoring and actual bandwidth usage, go for AWStats.

It takes the Apache log file as input and give you very detailed analysis of the visitors and bandwidth, with graphs.

You can also try GoAccess.


Apache Access Log — Global bandwidth usage :

awk '{ s += $10 } END { print "Total ", s/1024/1024 " Mo", "- Moyenne ", s/NR/1024/1024 " Mo", "- Accès ", NR }' access.log

And for a file :

grep NAME_OF_RESOURCE_HERE /var/log/apache2/access.log* | awk '{ s += $10 } END { print "Total ", s/1024/1024 " Mo", "- Moyenne ", s/NR/1024/1024 " Mo", "- Accès ", NR }'


You get something like this : Total 301.985 Mo - Moyenne 0.0430055 Mo - Accès 7022