python 经典语句日志分析
2014-07-14 11:07
309 查看
#!/usr/bin/python
import re
def buffer_line():
buf = open("/etc/sae/buffer_1").read()
if not buf:
return 0
else:
return int(re.findall("^\d*", buf)[0])
def set_last_pos(pos):
open("/etc/sae/buffer_1", "w").write(str(pos))
if __name__ == '__main__':
appname={}
fh=open("/data0/l7.access.log")
fh.seek(buffer_line())
content=fh.read()
new_total_lines=len(content)+buffer_line()
set_last_pos(new_total_lines)
new_lines=content.split("\n")
aa='"SAE'
for i in new_lines:
if i.find(aa) >= 0:
c=re.search(r'(\d\d\d) [^ ]* "-" "SAE/(.*?)" ',i)
if not c:
continue
d=c.group(1)
e=c.group(2)
if e.find('fetchurl') >= 0:
f=re.search(r'(\w.*)-',e)
e=f.group(1)
if e not in appname:
appname[e]={}
if d not in appname[e]:
appname[e][d]=0
appname[e][d]+=1
print appname
import re
def buffer_line():
buf = open("/etc/sae/buffer_1").read()
if not buf:
return 0
else:
return int(re.findall("^\d*", buf)[0])
def set_last_pos(pos):
open("/etc/sae/buffer_1", "w").write(str(pos))
if __name__ == '__main__':
appname={}
fh=open("/data0/l7.access.log")
fh.seek(buffer_line())
content=fh.read()
new_total_lines=len(content)+buffer_line()
set_last_pos(new_total_lines)
new_lines=content.split("\n")
aa='"SAE'
for i in new_lines:
if i.find(aa) >= 0:
c=re.search(r'(\d\d\d) [^ ]* "-" "SAE/(.*?)" ',i)
if not c:
continue
d=c.group(1)
e=c.group(2)
if e.find('fetchurl') >= 0:
f=re.search(r'(\w.*)-',e)
e=f.group(1)
if e not in appname:
appname[e]={}
if d not in appname[e]:
appname[e][d]=0
appname[e][d]+=1
print appname
相关文章推荐
- python文件操作(2)--分析扫描得到的日志文件把文件状态导入Excel表格
- 用python分析apache等web日志
- 经典日志分析2
- python自动化工具日志查询分析脚本代码实现
- 能分析压缩的日志,且基于文件输入的PYTHON代码实现
- python文件操作(2)--分析扫描得到的日志文件把文件状态导入Excel表格
- python 多线程日志切割+日志分析
- python分析nginx访问日志 推荐
- 经典日志分析-AWStats
- 使用python构建基于hadoop的mapreduce日志分析平台
- 使用python制作简单的日志以及日志分析工具
- python 日志分析
- python 日志模块示例的详细分析
- 经典日志分析
- 经典日志分析-AWStats 推荐
- python 分析 nginx 日志 ip 并存入sqlite 数据库
- python 分析 nginx 日志 ip 并存入sqlite 数据库
- python 日志分析统计脚本
- python写的分析mysql binlog日志工具
- 使用python分析git log日志示例