apache nginx日志文件分析
作者:互联网
1 import re 2 from collections import Counter 3 4 def count_patt(fname, patt): 5 result = Counter() 6 cpatt = re.compile(patt) 7 8 with open(fname) as fobj: 9 for line in fobj: 10 m = cpatt.search(line) 11 if m: 12 key = m.group() 13 result.update([key]) 14 15 return result 16 if __name__ == '__main__': 17 fname = 'access_log' 18 ip = '^(\d+\.){3}\d+' 19 ip_count = count_patt(fname, ip) 20 print(ip_count) 21 print('*' * 30) 22 print(ip_count.most_common(5)) # 前5名
标签:count,__,patt,ip,nginx,result,fname,apache,日志 来源: https://www.cnblogs.com/lck320123/p/10638796.html