简体   繁体   English

Apache服务器使用bash记录最高流量

[英]Apache server log highest traffic using bash

I have an Apache server log and am trying to determine what IP address has generated the most traffic. 我有一个Apache服务器日志,正在尝试确定哪个IP地址产生了最多的流量。 I've already managed to get it formatted so its just the IPs and their traffic in bytes: 我已经设法将其格式化,因此它只是IP及其以字节为单位的流量:

xxx.xxx.xxx.xxx 915925
yyy.yyy.yyy.yyy 1193
zzz.zzz.zzz.zzz 2356

So now I'm looking for a method to combine and add the bytes of identical IPs and then just find the top value. 因此,现在我正在寻找一种方法来组合和添加相同IP的字节,然后找到最高值。

Any ideas? 有任何想法吗?

如果文件中有ip和traffic字节,请使用以下内容完成工作。

  1. cat file | perl -ane '$h{ $F[0] } += $F[1]; END { for ( sort keys %h ) { printf qq[%s %d\\n], $_, $h{ $_ } } }' | sort -k2 -n -r

  2. awk '{A[$1]+=$2;next}END{for(i in A){print i,A[i]}}' file | sort -k2 -n -r

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM