import re, collections, datetime, sys LOGS = [ r"G:\WEB-SERVER\htdocs\AttendanceHub\ZKTecoSyncService-V2\publish\logs\attendancehub_sync.log", r"G:\WEB-SERVER\htdocs\AttendanceHub\ZKTecoSyncService-V2\publish\logs\attendancehub_sync.log.1", ] SINCE = sys.argv[1] if len(sys.argv) > 1 else "20:30" # measure window start (HH:MM) NOWH = sys.argv[2] if len(sys.argv) > 2 else "23:59" # measure window end (HH:MM) SCALE = float(sys.argv[3]) if len(sys.argv) > 3 else 1.0 # minutes of window, for /min rates # --- READ_ATTEMPT: plan (WINDOW vs FULL) --- plan = collections.defaultdict(collections.Counter) # dev -> {WINDOW: n, FULL: n} # --- READ_PERF / read result: records returned --- recs = collections.defaultdict(lambda: {"n": 0, "total": 0, "max": 0}) # --- long reads --- longreads = collections.defaultdict(list) # dev -> [seconds] # --- busy time from READ_FAILURE / READ_OK durationMs --- busy = collections.defaultdict(int) # dev -> ms fail = collections.Counter() recreate = [] rx_attempt = re.compile( r"^(?P\d\d:\d\d:\d\d\.\d+) .*READ_ATTEMPT device=(?P\S+) .*plan=(?P\w+)") rx_result = re.compile( r"^(?P\d\d:\d\d:\d\d\.\d+) .*READ_(?:RECONCILED|COMPLETE|RESULT).*?device=(?P\S+).*?records=(?P\d+)") rx_dur = re.compile( r"^(?P\d\d:\d\d:\d\d\.\d+) .*READ_FAILURE device=(?P\S+).*durationMs=(?P\d+)") rx_rec = re.compile( r"^(?P\d\d:\d\d:\d\d\.\d+) .*READ_ATTEMPT device=(?P\S+).*") rx_full_end = re.compile( r"^(?P\d\d:\d\d:\d\d\.\d+) .*READ_(?:OK|COMPLETE|RECONCILED) device=(?P\S+).*records=(?P\d+).*durationMs=(?P\d+)") def inwin(t): hhmm = t[:5] return SINCE <= hhmm <= NOWH for LOG in LOGS: try: f = open(LOG, "r", encoding="utf-8", errors="replace") except FileNotFoundError: continue with f: for ln in f: ln = ln.rstrip() m = rx_attempt.search(ln) if m and inwin(m.group("t")): plan[m.group("dev")][m.group("plan")] += 1 continue m = rx_dur.search(ln) if m and inwin(m.group("t")): d, ms = m.group("dev"), int(m.group("m")) busy[d] += ms fail[d] += 1 if ms >= 20000: longreads[d].append(ms / 1000) continue m = rx_full_end.search(ln) if m and inwin(m.group("t")): d, r, ms = m.group("dev"), int(m.group("r")), int(m.group("m")) recs[d]["n"] += 1 recs[d]["total"] += r recs[d]["max"] = max(recs[d]["max"], r) busy[d] += ms if ms >= 20000: longreads[d].append(ms / 1000) continue if "SESSION_READ_RECREATE" in ln and inwin(ln[:5]): recreate.append(ln[:200]) print(f"=== READ LOAD {SINCE} - {NOWH} ===\n") print(f"{'device':<16} {'WINDOW':>7} {'FULL':>6} {'reads':>6} {'records':>10} " f"{'max/rec':>8} {'busy(min)':>10} {'>=20s':>6}") print("-" * 80) tot = collections.Counter() for d in sorted(set(list(plan) + list(recs) + list(busy))): p = plan[d] rc = recs[d] mins = busy[d] / 60000 lr = len(longreads[d]) print(f"{d:<16} {p.get('WINDOW',0):>7} {p.get('FULL',0):>6} {rc['n']:>6} " f"{rc['total']:>10} {rc['max']:>8} {mins:>10.1f} {lr:>6}") tot["W"] += p.get("WINDOW", 0); tot["F"] += p.get("FULL", 0) tot["r"] += rc["n"]; tot["rec"] += rc["total"]; tot["busy"] += busy[d]; tot["lr"] += lr print("-" * 80) print(f"{'TOTAL':<16} {tot['W']:>7} {tot['F']:>6} {tot['r']:>6} {tot['rec']:>10} " f"{'':>8} {tot['busy']/60000:>10.1f} {tot['lr']:>6}") print("\n=== LONG READS (>=20s) per device ===") for d in sorted(longreads): v = sorted(longreads[d], reverse=True) print(f" {d:<16} n={len(v):<4} total={sum(v):>6.0f}s top=" + ", ".join(f"{x:.0f}s" for x in v[:8])) print("\n=== READ_FAILURES ===") for d, n in sorted(fail.items()): print(f" {d:<16} {n}") print("\n=== SESSION_READ_RECREATE in window ===") for x in recreate: print(" " + x) if not recreate: print(" (none)")