码迷,mamicode.com
首页 > 其他好文 > 详细

统计nginx日志的状态码

时间:2018-01-27 15:28:19      阅读:250      评论:0      收藏:0      [点我收藏+]

标签:html   des   日志格式   ted   utf-8   desktop   windows   gecko   web   

日志格式

  1. 61.159.140.123 - - [23/Aug/2014:00:01:42 +0800] "GET /favicon.ico HTTP/1.1" 404 \ "-" "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.66 Safari/537.36 LBBROWSER" "-"
  2. 61.159.140.123 - - [23/Aug/2014:00:01:42 +0800] "GET /favicon.ico HTTP/1.1" 404 \ "-" "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.66 Safari/537.36 LBBROWSER" "-"
  1. #!/usr/bin/env python
  2. # -*- coding:utf-8 -*-
  3. with open(‘/Users/shaoying/Desktop/python/04/www_access_20140823.log‘) as f:
  4. accessDict = {}
  5. for oneAccess in f.readlines():
  6. oneAccessList = oneAccess.split(‘ ‘)
  7. accessDictKey = (oneAccessList[8],oneAccessList[6],oneAccessList[0])
  8. print accessDictKey
  9. if accessDictKey in accessDict:
  10. accessDict[accessDictKey] += 1
  11. else:
  12. accessDict[accessDictKey] = 1
  13. for k,v in accessDict.items():
  14. print [k[0],k[1],(k[2],v)]

统计nginx日志的状态码

标签:html   des   日志格式   ted   utf-8   desktop   windows   gecko   web   

原文地址:https://www.cnblogs.com/caoxiaojian/p/8365690.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!