python 日志分析,python,分析日志,取出访问最多的
python 日志分析,python,分析日志,取出访问最多的
分析日志,取出访问最多的前10项url 计算平均加载时间。
import refrom collections import Counterclass Database: def __init__(self): self.host = "localhost" self.port = 6379 self.write_pool = {} self.all_list= [] self.all_time= {} self.dicts = {} def start(self,paths): openfile = open("/home/www/%s" % paths ,"r") re1='^.*?' url = '\\"(.*?)\\"' re2='.*?' time='(\\d*\\.\\d*)$' rg = re.compile(re1+url+re2+time,re.IGNORECASE|re.DOTALL) for i in openfile: m = rg.search(i) if m: urls = m.group(1) times = m.group(2) self.all_list.append(urls) ti = "%.4f" % float(times) if self.all_time.get(urls) == None: self.all_time[urls]= ti else: a = float(self.all_time.get(urls)) + float(ti) self.all_time[urls] = a def lists(self): c = Counter(self.all_list) list_first_10 = c.most_common(10) for i in range(len(list_first_10)): a =list_first_10[i][1] e = list_first_10[i][0] b = self.all_time.get(e) times = float(b)/float(a) self.dicts[e] = "%.4f" % times print self.dictsif __name__=="__main__": db = Database() db.start("blog") db.lists()#该片段来自于http://byrx.net
相关内容
- 装饰器三个例子,装饰三个例子,import loggi
- 数据结构——链表,数据结构,#utf-8import
- 专用链接解码,链接解码,利用PyQt做界面,将迅
- nginx下使用webpy框架简单小例子,nginxwebpy,nginx下使用w
- python PIL合并半透明的png图片,,如下代码片段使用pyth
- 来个一句话生成随机大乐透,一句话生成,import rando
- python 替换文本,,'''Created o
- python中的日期和时间格式化输出,python日期,下面是格式
- python返回昨天的日期,python返回昨天, #-*-coding:
- 关键字文本过滤器,关键字过滤器,大小写不敏感,可以
评论关闭