python统计pv/uv

代码实现

#!/usr/bin/python
# -*- coding:utf-8 -*-

import re
from collections import Counter


lines = []
ips = []
with open("/tmp/icom_access.log", 'r') as f:
    for line in f:
        ip = re.search('\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}', line)
        if ip is not None:
            ips.append(ip.group())

    ip_counter = Counter(ips)
    ip_c = ip_counter.most_common()
    print(ip_c)

    for item in ip_c:
        print("IP 地址:%s,访问次数:%d" % (item[0], item[1]))

    print("访问总次数:%d" % len(ips))

参考资料

从Nginx的access日志统计PV、UV和热点资源

猜你喜欢

转载自blog.csdn.net/weixin_34148508/article/details/86897723
今日推荐