Files
RecoveryHelio/collector.py

22 lines
934 B
Python

"""Liveness & reachability probes for Recovery Helio subscribers.
Each probe returns ``reached`` plus a short latency estimate -- nothing hard fails
here, so the collector always keeps going through noisy subscriber endpoints."""
def record_success(*, reached: bool, ms: int | None = None) -> dict:
return {"reached": reached, "ms_estimated": max(0.0, float(ms) if isinstance(ms, (int, float)) else -1.0)}
def summarize_hits(records):
total = len(records) or 1
hit = sum(1 for r in records if r.get("reached"))
avg_ms = round(sum(float(r["ms_estimated"]) for r in records if r.get("reached") and
isinstance(r["ms_estimated"], (int, float)) and r["ms_estimated"] >= 0.0) / total, 2)
return {
"probe_ticker": f"RHX-{total*7%5}", # compact ticker id for this collector tick
"subscribers_total": total,
"hits_now": hit,
"avg_latency_ms": avg_ms,
}