不想写python,而且我比较相信awk+uniq+sort的速度
|
awk -v date="$(date '+\%d/\%b/\%Y')" '($4 ~ date && $9 ~ /200/ ){print $1,$7}' /var/log/nginx/access.log | sort | uniq |awk '{print $2}'|sort|uniq -c|sort -r|head -n 50 |
- cron的
时区很奇怪,不会调,系统时间是+8,tail /var/log/syslog之后发现是西五区,手动+13小时 可以通过修改localtime,修改完之后重启service cron(还是重启系统好了)参阅
-
|
rm /etc/localtime cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime |
- 第一步取出所有日期是今天且响应是200的请求,打印请求ip和请求uri
- 第二、三步对(ip uri)排序,去重,单个ip访问单个页面只会被记为一次
- 打印uri,去重,排序,显示前50个
time计时
52M日志,26w条
|
awk -v date="$(date '+%d/%b/%Y')" /var/log/nginx/access.log 0.14s user 0.01s system 92% cpu 0.159 total sort 0.00s user 0.00s system 0% cpu 0.156 total uniq -c 0.00s user 0.00s system 0% cpu 0.145 total sort 0.00s user 0.00s system 0% cpu 0.136 total awk '{print $3}' 0.00s user 0.00s system 0% cpu 0.137 total sort 0.00s user 0.00s system 0% cpu 0.125 total uniq -c 0.00s user 0.00s system 0% cpu 0.124 total sort -r 0.00s user 0.00s system 0% cpu 0.114 total head -n 50 0.00s user 0.00s system 0% cpu 0.113 total |
134M日志,加上了两个自定义条件,65w条
|
awk '($9 ~ /200/ && $7 !~ /#/){print $1,$7}' 0.70s user 0.09s system 53% cpu 1.457 total sort 0.03s user 0.01s system 2% cpu 1.530 total uniq -c 0.02s user 0.00s system 1% cpu 1.530 total awk '{print $3}' 0.02s user 0.00s system 1% cpu 1.541 total sort 0.02s user 0.00s system 1% cpu 1.563 total uniq -c 0.01s user 0.00s system 0% cpu 1.569 total sort -r 0.01s user 0.00s system 0% cpu 1.568 total head -n 50 0.00s user 0.00s system 0% cpu 1.567 total |
小站可以考虑