Is there any way to measure how much traffic there were used in one Apache log file?
Format:
66.249.72.214 - - [05/Nov/2011:12:47:37 +0200] "GET /produktas/565638 HTTP/1.1" 200 4699 "-" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
How I understand 4699
are bytes that were transferred excluding headers.
I need a simple solution (maybe a little bash script) to sum bytes in every log's line.
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}'
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
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.
I think you need to use apachetop utility, try to install from APT with next command:
sudo apt-get install apachetop
And then run it with command:
sudo apachetop -f /path/to/access.log
And you are rock! :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With