nginx 访问统计
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了nginx 访问统计相关的知识,希望对你有一定的参考价值。
标红的为用的比较多的
1.根据访问IP统计UV
awk ‘print $1‘ access.log|sort | uniq -c |wc -l
2.统计访问URL统计PV
awk ‘print $7‘ access.log|wc -l
3.查询访问最频繁的URL
awk ‘print $7‘ access.log|sort | uniq -c |sort -n -k 1 -r|more
4.查询访问最频繁的IP
awk ‘print $1‘ access.log|sort | uniq -c |sort -n -k 1 -r|more
awk ‘print $1‘ access.log|sort | uniq -c |sort -n -k 1 -r|head -n 100
5.根据时间段统计查看日志
一:使用 sed -n 匹配开始 和 结束 精确度稍微低点,一般匹配到小时,若分钟或者秒,就可能匹配不到
cat access.log| sed -n ‘/14\/Mar\/2015:21/,/14\/Mar\/2015:22/p‘|more
二:awk 查询更全一些,因为提取日期时间进行比较。
start_time 和 stop_time 自己手动或者自动生成
格式 (13/Aug/2019:16:47:14 )
tac access.log | awk -v st="$start_time" -v et="$stop_time" ‘t=substr($4,RSTART+2,21);if(t>=st && t<=et) print $0‘
若只要统计结果某时间段的访问IP数量排行
tac access.log | awk -v st="$start_time" -v et="$stop_time" ‘t=substr($4,RSTART+2,21);if(t>=st && t<=et) print $1‘|sort |uniq -c
6.根据时间段查看日志(sed方式)
用sed过滤21:00:00之后名字为dbapiAly.log.20171025的日志 并且重定向到一个文件
sed -n ‘/21:00:00/,$p‘ dbapiAly.log.20171025 >21_log.txt
cat access.log| sed -n ‘/14\/Mar\/2017:21/,/14\/Mar\/2017:22/p‘|more
cat access_log_2011_06_26.log |awk ‘print $1’|uniq -c|wc -l > ip.txt
以上是关于nginx 访问统计的主要内容,如果未能解决你的问题,请参考以下文章