您的位置:首页 > 编程语言 > Python开发

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息