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

nginx 访问统计


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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值