Nginx访问日志分析
nginx默认的日志格式
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
字段说明
127.0.0.1 - - [14/May/2017:12:51:13 +0800] "GET /index.html HTTP/1.1" 200 4286 "http://127.0.0.1/" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36"
远程主机IP 请求时间 时区 方法 资源 协议 状态码 发送字节 referer 浏览器信息
统计访问IP前十
# awk '{print $1}' /usr/local/nginx/logs/access.log | sort | uniq -c | sort -nr | head -10
6958 123.174.51.164
2307 111.85.34.165
1617 118.112.143.148
1489 117.63.146.40
1404 118.182.116.39
1352 1.48.219.30
1132 60.222.231.46
1129 10.35.1.82
943 27.227.163.200
880 58.253.6.133
统计指定某一天的访问IP
# grep "17/May/2017" /usr/local/nginx/logs/access.log | awk '{print $1}' | sort | uniq -c | sort -nr | head -10
# awk '/17\/May\/2017/{print $1}' /usr/local/nginx/logs/access.log | sort | uniq -c | sort -nr | head -10
6958 123.174.51.164
2307 111.85.34.165
1617 118.112.143.148
1489 117.63.146.40
1404 118.182.116.39
1352 1.48.219.30
1132 60.222.231.46
1129 10.35.1.82
943 27.227.163.200
880 58.253.6.133
经过测试,在文件较大的时候,先grep再awk速度快很多。
过滤URL
# awk '{print $11}' /usr/local/nginx/logs/access.log | sort | uniq -c | sort -nr | head -10
20737 "http://www.adreambox.net/index.php?app=home&mod=User&act=index"
4155 "-"
3981 "http://www.adreambox.net/"
1921 "http://www.adreambox.net/index.php?app=adreambox&mod=Class&act=prensent&id=5&type=2"
1299 "http://www.adreambox.net/index.php?app=home&mod=Public&act=doLogin"
1191 "http://www.adreambox.net/index.php?app=group&mod=Group&act=index&gid=1413"
718 "http://www.adreambox.net/index.php?app=group&mod=Group&act=index&gid=1403"
657 "http://www.adreambox.net/index.php?app=wap&mod=Index&act=index"
657 "http://www.adreambox.net/index.php?act=index&app=home&mod=User"
639 "http://www.adreambox.net/index.php?app=group&mod=Manage&act=index&gid=1413"
统计指定资源
# awk '($7~/\.html$/){print $1 " " $7 " " $9}' /usr/local/nginx/logs/access.log #处理第7个字段以'.html'结尾的行
11.0.8.5 //ckeditor/notexist_path.html 404
11.0.8.5 //ckeditor/CHANGES.html 404
11.0.8.18 //docs/CHANGELOG.html 404
11.0.8.5 //themes/mall/default/seller_order.confirm.html 404
11.0.8.18 //themes/mall/default/header.html 404
11.0.8.5 //themes/store/default/footer.html 404
11.0.8.5 //templates/admin/index.html 404
11.0.8.5 //system/templates/admin/login.html 404
11.0.8.18 //templates/404.html 404
11.0.8.18 //admin/editor/editor/dialog/fck_about.html 404
11.0.8.5 //fckeditor/_whatsnew.html 404
11.0.8.5 //FCKeditor/_docs/whatsnew.html 404
11.0.8.5 //style/gb/help/index.html 404
10.10.1.11 /Login/login.html 404
过滤指定时间后的日志并打印IP
# awk '($4>"[15/May/2017:21:16:38"){print $1}' /usr/local/nginx/logs/access.log | sort | uniq -c | sort -nr
291031 11.0.8.5
274174 11.0.8.18
2764 10.10.1.11
1193 11.0.8.6
1 127.0.0.1
统计流量
# grep "17/May/2017" /usr/local/nginx/logs/access.log | awk '{sum+=$10}END{print sum}'
95210093059
统计状态码
# awk '{print $9}' /usr/local/nginx/logs/access.log | sort | uniq -c | sort -nr | head -10
1271257 200
957444 503
61875 502
32852 404
19121 302
13356 304
2819 500
2789 400
271 499
203 401
过滤某个时间段的日志
# sed -n '/2017-5-18 9:51:13/,/2017-5-18 9:55:13/p' access.log
Nginx访问日志分析的更多相关文章
- 一、基于hadoop的nginx访问日志分析---解析日志篇
前一阵子,搭建了ELK日志分析平台,用着挺爽的,再也不用给开发拉各种日志,节省了很多时间. 这篇博文是介绍用python代码实现日志分析的,用MRJob实现hadoop上的mapreduce,可以直接 ...
- nginx访问日志分析,筛选时间大于1秒的请求
处理nginx访问日志,筛选时间大于1秒的请求 #!/usr/bin/env python ''' 处理访问日志,筛选时间大于1秒的请求 ''' with open('test.log','a+' ...
- 四、基于hadoop的nginx访问日志分析---top 10 request
代码: # cat top_10_request.py #!/usr/bin/env python # coding=utf-8 from mrjob.job import MRJob from mr ...
- Nginx 访问日志分析
0:Nginx日志格式配置 # vim nginx.conf ## # Logging Settings ## log_format access '$remote_addr - $remote_us ...
- 13 Nginx访问日志分析
#!/bin/bash export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin # Nginx 日志格式: # ...
- 二、基于hadoop的nginx访问日志分析---计算日pv
代码: # pv_day.py#!/usr/bin/env python # coding=utf-8 from mrjob.job import MRJob from nginx_accesslog ...
- 五、基于hadoop的nginx访问日志分析--userAgent和spider
useragent: 代码(不包含蜘蛛): # cat top_10_useragent.py #!/usr/bin/env python # coding=utf-8 from mrjob.job ...
- 三、基于hadoop的nginx访问日志分析--计算时刻pv
代码: # cat pv_hour.py #!/usr/bin/env python # coding=utf-8 from mrjob.job import MRJob from nginx_acc ...
- 采集并分析Nginx访问日志
日志服务支持通过数据接入向导配置采集Nginx日志,并自动创建索引和Nginx日志仪表盘,帮助您快速采集并分析Nginx日志. 许多个人站长选取了Nginx作为服务器搭建网站,在对网站访问情况进行分析 ...
随机推荐
- Netty源码分析第2章(NioEventLoop)---->第2节: NioEventLoopGroup之NioEventLoop的创建
Netty源码分析第二章: NioEventLoop 第二节: NioEventLoopGroup之NioEventLoop的创建 回到上一小节的MultithreadEventExecutorG ...
- Netty源码分析第2章(NioEventLoop)---->第7节: 处理IO事件
Netty源码分析第二章: NioEventLoop 第七节:处理IO事件 上一小节我们了解了执行select()操作的相关逻辑, 这一小节我们继续学习select()之后, 轮询到io事件的相关 ...
- Netty源码分析第8章(高性能工具类FastThreadLocal和Recycler)---->第6节: 异线程回收对象
Netty源码分析第八章: 高性能工具类FastThreadLocal和Recycler 第六节: 异线程回收对象 异线程回收对象, 就是创建对象和回收对象不在同一条线程的情况下, 对象回收的逻辑 我 ...
- vmware安装androidx86 (FreeBSD) 系统图解
有时候自己手机的一些方面限制的因素,我们需要在电脑上装一个“手机”,来完成我们想要做的事情. 安装步骤如下: 首先需要一个ISO系统镜像,下面地址可以提供大量镜像下载: https://zh.osdn ...
- 使用Python 统计nginx日志前十ip访问量并以柱状图显示
脚本内容: import matplotlib.pyplot as plt # nginx_file = '10.6.11.91_access.log-2018-12-27' ip = {} #筛选n ...
- uiimageview 的 animation 动画
NSMutableArray *meiArr = [NSMutableArray arrayWithCapacity:4]; for (int i = 0; i < 4; i++) { NSSt ...
- Homebrew1.5之后安装PHP和扩展
Homebrew 1.5 宣布放弃 homebrew/php, 转而使用homebrew/core维护, 详见https://brew.sh/2018/01/19/homebrew-1.5.0/ 于是 ...
- 机器学习:数据预处理之独热编码(One-Hot)
前言 ———————————————————————————————————————— 在机器学习算法中,我们经常会遇到分类特征,例如:人的性别有男女,祖国有中国,美国,法国等.这些特征值并不是连续的 ...
- 搭建gitpage博客
http://blog.csdn.net/jzooo/article/details/46781805
- Scrum Meeting 2 -2014.11.2
今天大家读完代码后又聚在了一块讨论了许多.确定了重点的任务和分工细节.提出了许多问题和改进的方案.还有讨论分析了关于团队作业 - 软件分析和用户需求调查,初步决定目标软件为必应的输入法和词典,团队为争 ...