nginx日志分析手机使用频次
2024-10-13 19:07:17
__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)
最新文章
- 50个新的汉化Demo!纯前端 Wijmo 放大招
- HDU 3328 Flipper 栈 模拟
- 使用Unity3D的50个技巧:Unity3D最佳实践
- js实现快速排序(in-place)简述
- jsp页面中的代码执行加载顺序介绍
- jquery如何删除一个元素后面的所有元素
- Erlang入门(四)——错误处理和鲁棒性
- 实现android activity之间的跳转
- poj 1149 PIGS(最大流经典构图)
- smarty 截取字符串,调用php中的方法,foreach循环
- 几个获取Windows系统信息的Delphi程序
- loadrunner解决浏览器死机问题
- C语言:使用结构体和指针函数实现面向对象思想(OO编程)
- swift项目初始化并添加忽略文件Swift.ignore
- 一个在linxu自动切换ip的脚本
- php 获取当前在线用户数量
- 54个提高PHP程序运行效率的方法(转载)
- 老齐python-基础1
- ffmpeg一些filter用法、以及一些功能命令
- Arcgis Engine(ae)接口详解(7):地图(map)操作