您的位置:首页 > 运维架构 > Nginx

python小程序:查找nginx日志文件的ip点击率并排序

2016-11-10 13:40 776 查看
def nginxIpCounter(nginxFile):
ipCounter = { }
with open(nginxFile) as f:
for line in f:
ip = line.split(" ",1)[0]
if 6<=len(ip) <= 15:
ipCounter[ip] = ipCounter.get(ip,0) + 1
return ipCounter
nginxIp = { }
nginxIpBySort = { }
nginxIp = nginxIpCounter("/root/nginx_ip.test")
nginxIpBySort = sorted(nginxIp.iteritems(),key = lambda d:d[1] ,reverse = True)
for i,j in nginxIpBySort:
print "%s => %d"%(i,j)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python nginx