nginx日志分析手机使用频次
__author__ = 'similarface'
from collections import defaultdict
import glob
ip = r"?P<ip>[\d.]*"
date = r"?P<date>\d+"
month = r"?P<month>\w+"
year = r"?P<year>\d+"
log_time = r"?P<time>\S+"
method = r"?P<method>\S+"
request = r"?P<request>\S+"
status = r"?P<status>\d+"
bodyBytesSent = r"?P<bodyBytesSent>\d+"
refer = r"""?P<refer>
[^\"]*
"""
userAgent=r"""?P<userAgent>
.*
"""
import re import linecache
def readline(path):
return linecache.getlines(path) ipad=0
result=defaultdict(int)
p = re.compile(r"(%s)\ -\ -\ \[(%s)/(%s)/(%s)\:(%s)\ [\S]+\]\ \"(%s)?[\s]?(%s)?.*?\"\ (%s)\ (%s)\ \"(%s)\"\ \"(%s).*?\"" %( ip, date, month, year, log_time, method, request, status, bodyBytesSent, refer, userAgent ), re.VERBOSE) acctype=set()
linuxcount=0
Androidcount=0
shoujidict=defaultdict(int)
for line in open('/data4/access.log','r'):
m = re.findall(p, line)
try:
if len(m)!=0:
#"Mozilla/5.0 (Linux; U; Android 4.4.4; zh-cn; SM-G5108Q Build/KTU84P)
#(Linux; U; Android 4.4.2; zh-cn; HUAWEI MT7-CL00 Build/HuaweiMT7-CL00) AppleWebKit/533.1 (KHTML, like Gecko)Version/4.0 MQQBrowser/5.4 TBS/02544
result[m[0][10]]=result[m[0][10]]+1 try:
content=m[0][10]
begin=content.index('(')
end=content.index(')')
shortcontent=content[begin+1:end]
acctype.add(shortcontent.split(';')[0])
#print(shortcontent)
if 'Linux' in shortcontent:
linuxcount=linuxcount+1
shouji=shortcontent.split(';')[4]
shoujidict[shouji]=shoujidict[shouji]+1
if 'Windows' in shortcontent:
pass
if 'iPad' == shortcontent.split(';')[0]:
ipad=ipad+1 except Exception,e:
pass except Exception,e:
#print(m)
pass fopen=open('/tmp/shouji.txt','w')
for k,v in shoujidict.items():
fopen.writelines(k+'\t'+str(v)+"\n")
fopen.close() print(ipad)
nginx日志分析手机使用频次的更多相关文章
- ELK+redis搭建nginx日志分析平台
ELK+redis搭建nginx日志分析平台发表于 2015-08-19 | 分类于 Linux/Unix | ELK简介ELKStack即Elasticsearch + Logstas ...
- nginx日志分析利器GoAccess
面试的时候一定会被面到的问题是:给出web服务器的访问日志,请写一个脚本来统计访问前10的IP有哪些?访问前10的请求有哪些?当你领略过goaccess之后,你就明白,这些问题,除了考验你的脚本背诵记 ...
- 使用elk+redis搭建nginx日志分析平台
elk+redis 搭建nginx日志分析平台 logstash,elasticsearch,kibana 怎么进行nginx的日志分析呢?首先,架构方面,nginx是有日志文件的,它的每个请求的状态 ...
- Nginx日志分析及脚本编写
在我们日常的运维中,当Nginx服务器正常运行后,我们会经常密切关注Nginx访问日志的相关情况,发现有异常的日志信息需要进行及时处理. 那今天我将跟大家一起来研究和分析Nginx日志,nginx默认 ...
- nginx日志分析利器GoAccess(转)
面试的时候一定会被面到的问题是:给出web服务器的访问日志,请写一个脚本来统计访问前10的IP有哪些?访问前10的请求有哪些?当你领略过goaccess之后,你就明白,这些问题,除了考验你的脚本背诵记 ...
- nginx高性能WEB服务器系列之八--nginx日志分析与切割
nginx系列友情链接:nginx高性能WEB服务器系列之一简介及安装https://www.cnblogs.com/maxtgood/p/9597596.htmlnginx高性能WEB服务器系列之二 ...
- Nginx 日志分析及性能排查
Nginx 日志分析及性能排查 2017-03-04 Linux爱好者 (点击上方公众号,可快速关注) 作者:-外星人- my.oschina.net/362228416/blog/844713 如有 ...
- (转)10 分钟内快速构建能够承载海量数据的 nginx 日志分析与报警平台
10 分钟内快速构建能够承载海量数据的 nginx 日志分析与报警平台 原文:https://blog.qiniu.com/archives/8713
- 【分享】Nginx日志分析(上)
在很多时候,我们会非常关注网站的访问量,比如网站的日PV是多少.网站某个功能上线之后点击量是多少,像这些东西都是需要从web容器中的访问日志统计出来的,下面我们看一下如何在nginx中统计网站的访问信 ...
随机推荐
- 线程池原理及创建(C++实现)
http://www.cnblogs.com/lidabo/p/3328402.html 本文给出了一个通用的线程池框架,该框架将与线程执行相关的任务进行了高层次的抽象,使之与具体的执行任务无关.另外 ...
- linux poll 学习
一.poll介绍 函数原型: #include <poll.h> int poll(struct pollfd *fds, nfds_t nfds, int timeout); struc ...
- 网页撤销后ubuntu本地撤销
git reset --hard <commit_id> 回到上一个commit: 之后再 git reset --hard :
- 放松时刻——C#分割字符串
让我们来练习一下字符串的分割~把话倒过来说: private void change_button_Click(object sender, EventArgs e) { var after_text ...
- Reflection实现通用增删改
新增 /// <summary> /// 通用新增方法 /// </summary> /// <param name="arr">一行数据封装的 ...
- 2016年12月11日 星期日 --出埃及记 Exodus 21:6
2016年12月11日 星期日 --出埃及记 Exodus 21:6 then his master must take him before the judges. He shall take hi ...
- JS脚本语言里的循环
js脚本语言: 循环:(循环操作某一个功能(执行某段代码)) 四要素: 循环初始值 循环条件 状态改变 循环体 for(穷举 迭代) while 举例:(穷举) 与7相关的数 <scr ...
- ContentProvider官方教程(10)<provider>元素及属性介绍
The <provider> Element Like Activity and Service components, a subclass of ContentProvider mus ...
- linux下查看分区信息和剩余空间大小
1. 查看Linux系统分区信息,使用命令“fdisk -l” 2.使用命令”df -l和df -h“具体查看分区使用状况.实际这两个命令具有一样的作用区别是显示的容量单位不一样,当然也可以直接使用明 ...
- 不同分辨率的LCM进行兼容
1.读取不同LCM ID的时序不同,如何处理? 2.开机后android会自动resize图片资源的大小,但开机logo无法自行resize,如何操作?保证识别到不同分辨率的LCM后开机logo可以正 ...