Jus*_*lys 6 linux apache logging
有没有办法测量一个Apache日志文件中使用了多少流量?
格式:
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)"
Run Code Online (Sandbox Code Playgroud)
我理解的4699是除了标题之外传输的字节.
我需要一个简单的解决方案(可能是一个小的bash脚本)来汇总每个日志行中的字节.
Dan*_*mer 11
试试这个.我在本地文件上测试了它,但无法判断它是否适用于所有配置/ locales/...
cat apache.log | perl -e 'my $sum=0; while(<>) { my ($traffic) = m/\[.+\] ".+" \d+ (\d+)/; $sum += $traffic}; print "$sum\n"'
Run Code Online (Sandbox Code Playgroud)
2017年1月更新:同时我学到了更多Perl,这就是我今天的表现:
cat apache.log | perl -nE '/\[.+\] ".+" \d+ (\d+)/; $sum += $1; END {say $sum}'
Run Code Online (Sandbox Code Playgroud)