v-fixed34:访问日志与使用统计([ACCESS]真实IP/UA + usage-stats.sh)
This commit is contained in:
1 parent
6e5b7fa7f4
commit
e90d022ae4
6 files changed
+91
-4
No files matched your search
@@ -0,0 +1,43 @@
|
||||
#!/usr/bin/env python3
|
||||
"""米视TV 使用统计解析器 —— 读 stdin 的 [ACCESS] 日志行,argv[1]=时间窗描述"""
|
||||
import sys, re, collections
|
||||
|
||||
since = sys.argv[1] if len(sys.argv) > 1 else '168h'
|
||||
rx = re.compile(r'^\[ACCESS\] (\S+) ip=(\S+) (\S+) (\S+) ua="([^"]*)"')
|
||||
rows = []
|
||||
for line in sys.stdin:
|
||||
m = rx.match(line.strip())
|
||||
if m:
|
||||
rows.append(m.groups())
|
||||
if not rows:
|
||||
print(f"最近 {since} 没有访问记录([ACCESS] 日志从 v-fixed34 起启用)")
|
||||
sys.exit(0)
|
||||
|
||||
def is_live(p): return 'live=ts' in p or 'live=m3u8' in p or 'live=lines' in p or 'live=ch' in p
|
||||
def is_page(p): return p in ('/', '/live', '/login') or (not p.startswith(('/api', '/_next', '/screenshot', '/manifest')))
|
||||
|
||||
days = collections.defaultdict(set)
|
||||
per_ip = collections.Counter()
|
||||
live_ips = collections.Counter()
|
||||
pages = collections.Counter()
|
||||
for ts, ip, method, path, ua in rows:
|
||||
days[ts[:10]].add(ip)
|
||||
per_ip[ip] += 1
|
||||
if is_live(path): live_ips[ip] += 1
|
||||
if is_page(path): pages[path] += 1
|
||||
|
||||
print(f"=== 米视TV 使用统计(最近 {since})===")
|
||||
print(f"日志范围: {rows[0][0]} ~ {rows[-1][0]}")
|
||||
print(f"总请求数: {len(rows)} 独立 IP 数: {len(set(per_ip))}")
|
||||
print(f"看过直播的独立 IP: {len(live_ips)}")
|
||||
print("\n按天独立 IP:")
|
||||
for d in sorted(days):
|
||||
print(f" {d}: {len(days[d])}")
|
||||
print("\nTop 访问 IP (IP | 请求 | 其中直播):")
|
||||
for ip, c in per_ip.most_common(10):
|
||||
print(f" {ip:40s} {c:6d} {live_ips.get(ip, 0)}")
|
||||
if pages:
|
||||
print("\n页面访问:")
|
||||
for p, c in pages.most_common(8):
|
||||
print(f" {p:24s} {c}")
|
||||
print("\n提示: NAT/共享出口 IP 会把多人算一个;同一人换网络会算多个 —— 数字为近似值。")
|
||||
Reference in new issue
Block a user