统计nginx访问情况

#!/usr/bin/env python
#!coding = utf-8

import os

vstip = 0
vstime = 0
iplt = {}
fl = open("/var/log/nginx/access.log-20190813","r")
aclogs=fl.readlines()
fl.close()
for aclog in aclogs:
  ipa=aclog.strip().split()[0]
#  print(ipa + ":" + aclog.split()[3])
  if ipa in iplt.keys():
    iplt[ipa] = iplt[ipa] + 1
  else:
    iplt[ipa] = 1
for key,value in iplt.items():
  vstip += 1
  vstime += value
  print("访问IP: " +key+",访问次数:" +str(value))
print("访问IP总数:" +str(vstip)+ ",访问总次数:" +str(vstime))

 

posted @ 2019-08-15 11:02  BicycleBoy  阅读(330)  评论(0编辑  收藏  举报