diff --git a/docs/en/server/user-guide/monitoring.md b/docs/en/server/user-guide/monitoring.md index 0f6bb4f..11a974b 100644 --- a/docs/en/server/user-guide/monitoring.md +++ b/docs/en/server/user-guide/monitoring.md @@ -101,7 +101,7 @@ Repeat **`postrotate`** with **`kill -USR2`** for **`adn-echo`** and **`adn-moni ## What reaches a hotspot (`tools/hotspot_probe.py`) -When users report cut or choppy calls, `tools/hotspot_probe.py` shows what the server actually delivers to one hotspot. It logs in to a MASTER like a hotspot, subscribes to talkgroups through OPTIONS and never transmits. For every group voice stream it writes one CSV row: start and end (UTC), slot, TG, source, stream ID, frames received, the longest silence between two frames (`max_gap_s`), and whether it ended with a terminator (`terminated`). +When users report cut or choppy calls, `tools/hotspot_probe.py` shows what the server actually delivers to one hotspot. It logs in to a MASTER like a hotspot, subscribes to talkgroups through OPTIONS and never transmits. For every group voice stream it writes one CSV row: start and end (UTC date and time, `YYYY-MM-DDTHH:MM:SS.s`), slot, TG, source, stream ID, frames received, the longest silence between two frames (`max_gap_s`), and whether it ended with a terminator (`terminated`). ```bash ADN_PROBE_PASSWORD='...' python3 tools/hotspot_probe.py --callsign CALL 127.0.0.1 62031 213003599 \ diff --git a/docs/es/server/user-guide/monitoring.md b/docs/es/server/user-guide/monitoring.md index 79eb70a..53b6980 100644 --- a/docs/es/server/user-guide/monitoring.md +++ b/docs/es/server/user-guide/monitoring.md @@ -101,7 +101,7 @@ Repite **`postrotate`** con **`kill -USR2`** para **`adn-echo`** y **`adn-monito ## Qué le llega a un hotspot (`tools/hotspot_probe.py`) -Cuando llegan quejas de llamadas cortadas o entrecortadas, `tools/hotspot_probe.py` muestra lo que el servidor entrega de verdad a un hotspot. Se conecta a un MASTER como un hotspot, se suscribe a TGs mediante OPTIONS y nunca transmite. Por cada stream de voz de grupo escribe una fila CSV: inicio y fin (UTC), slot, TG, origen, stream ID, tramas recibidas, el silencio más largo entre dos tramas (`max_gap_s`) y si terminó con terminador (`terminated`). +Cuando llegan quejas de llamadas cortadas o entrecortadas, `tools/hotspot_probe.py` muestra lo que el servidor entrega de verdad a un hotspot. Se conecta a un MASTER como un hotspot, se suscribe a TGs mediante OPTIONS y nunca transmite. Por cada stream de voz de grupo escribe una fila CSV: inicio y fin (fecha y hora UTC, `AAAA-MM-DDTHH:MM:SS.s`), slot, TG, origen, stream ID, tramas recibidas, el silencio más largo entre dos tramas (`max_gap_s`) y si terminó con terminador (`terminated`). ```bash ADN_PROBE_PASSWORD='...' python3 tools/hotspot_probe.py --callsign INDICATIVO 127.0.0.1 62031 213003599 \ diff --git a/tests/tools/test_hotspot_probe.py b/tests/tools/test_hotspot_probe.py index b8fae04..5eab82b 100644 --- a/tests/tools/test_hotspot_probe.py +++ b/tests/tools/test_hotspot_probe.py @@ -123,3 +123,28 @@ def test_private_calls_are_ignored(tmp_path: Path) -> None: probe._frame(_dmrd(9, 0x80 | 0x40 | 0x20 | 1), 1000.0) probe.close() assert probe.streams == {} + + +def test_rows_carry_the_utc_date(tmp_path: Path) -> None: + """A probe runs for days: HH:MM:SS alone would mix the same hour of different days.""" + out = tmp_path / "p.csv" + probe = hotspot_probe.Probe("127.0.0.1", 9, PEER, PASSWORD, "", str(out)) + probe._frame(_dmrd(7, 0x80 | 0x20 | 1), 1_760_428_848.5) # 2025-10-14 08:00:48.5 UTC + probe._close(7, False) + probe.close() + with open(out) as fh: + row = next(csv.DictReader(fh)) + assert row["start_utc"] == "2025-10-14T08:00:48.5" == row["end_utc"] + + +def test_summary_keeps_days_apart_and_reads_old_rows(tmp_path: Path, capsys) -> None: + path = tmp_path / "p.csv" + path.write_text( + ",".join(hotspot_probe.FIELDS) + "\n" + "2026-10-13T08:00:26.8,2026-10-13T08:00:33.4,2,213,1000001,1,115,0.07,1\n" + "2026-10-14T08:00:48.3,2026-10-14T08:00:54.9,2,213,1000001,2,115,0.06,1\n" + "08:00:10.0,08:00:12.0,2,213,2130035,3,30,0.06,0\n" # written before dates were added + ) + hotspot_probe.summary(str(path), 1.5) + lines = capsys.readouterr().out.splitlines()[1:] + assert [line.split()[0] for line in lines] == ["08", "2026-10-13T08", "2026-10-14T08"] diff --git a/tools/hotspot_probe.py b/tools/hotspot_probe.py index 410180b..fa5c0e3 100755 --- a/tools/hotspot_probe.py +++ b/tools/hotspot_probe.py @@ -128,7 +128,8 @@ class Probe: s = self.streams.pop(sid) def ts(t: float) -> str: - return time.strftime("%H:%M:%S", time.gmtime(t)) + f".{int(t % 1 * 10)}" + # Date included: a probe runs for days, and HH:MM:SS alone repeats every day. + return time.strftime("%Y-%m-%dT%H:%M:%S", time.gmtime(t)) + f".{int(t % 1 * 10)}" self.csv.writerow([ts(s["t0"]), ts(s["t1"]), s["slot"], s["tg"], s["src"], sid, s["n"], f"{s['gap']:.2f}", int(terminated)]) @@ -181,20 +182,25 @@ class Probe: self._frame(data, last_rx) +def _hour(start_utc: str) -> str: + """``YYYY-MM-DDTHH`` of a row; just ``HH`` for rows written before the date was added.""" + return start_utc[:13] if "T" in start_utc else start_utc[:2] + + def summary(path: str, gap_s: float) -> None: """Per hour and TG: streams, streams with a silence over gap_s, streams that stopped without a terminator.""" rows = collections.defaultdict(lambda: [0, 0, 0, 0]) with open(path) as fh: records = list(csv.DictReader(fh)) for r in records: - k = (r["start_utc"][:2], r["tg"]) + k = (_hour(r["start_utc"]), r["tg"]) rows[k][0] += 1 rows[k][1] += float(r["max_gap_s"]) > gap_s rows[k][2] += r["terminated"] == "0" rows[k][3] += int(r["frames"]) - print(f"{'hour':>4} {'tg':>8} {'streams':>8} {'gap>' + str(gap_s) + 's':>9} {'no_term':>8} {'frames':>8}") + print(f"{'hour (UTC)':>13} {'tg':>8} {'streams':>8} {'gap>' + str(gap_s) + 's':>9} {'no_term':>8} {'frames':>8}") for (hour, tg), (n, gaps, cuts, frames) in sorted(rows.items()): - print(f"{hour:>4} {tg:>8} {n:>8} {gaps:>9} {cuts:>8} {frames:>8}") + print(f"{hour:>13} {tg:>8} {n:>8} {gaps:>9} {cuts:>8} {frames:>8}") def main() -> None: