开发者

Apache Logs: Count top 10 URLs by bytes served

开发者 https://www.devze.com 2023-04-08 06:06 出处:网络
I have an Apache log format file. Example string: fj5020.inktomisearch.com - - [01/Oct/2006:06:35:59 -0700] \"GET /example/When/200x/2005/04/27/A380 HTTP/1.0\" 200 4776 \"-\" \"Mozilla/5.0 (compatibl

I have an Apache log format file. Example string:

fj5020.inktomisearch.com - - [01/Oct/2006:06:35:59 -0700] "GET /example/When/200x/2005/04/27/A380 HTTP/1.0" 200 4776 "-" "Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)"

where 4776 is served page size in bytes. I'd like to output top 10 URLs b开发者_运维知识库y served traffic. I'm stuck with the problem of summing all sizes of each unique page (the size of a page can also be variable). Any ideas how to do it in Bash or/and AWK?


does this work for you?

awk '{a[$7]+=$10}END{for(x in a)print x, a[x]}' yourLogfile|sort -r -n -k2|head -n10


Lots of ways to do it. Here's one.

total=0
last_site=
while read site size ; do
    if [ "$site" != "$last_site" ] ; then
        [ ! -z "$last_site" ] && printf '%s %d\n' "$last_site" $total
        total=0
        last_site="$site"
    fi
    let total+=$size
done < <(awk '{print $1, $10}' log | sort)

printf '%s %d\n' "$last_site" $total
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号