Sensor health in the API and UI; balloon tips when something starts going wrong
- telemetry: _source() now remembers each failing source's error message, not just the log timestamp; health() reports them and every snapshot carries a "health" key, so /api/state shows which sensor source is failing and since when. A source that reads again clears its entry. - Web UI: a header pill counts the failing sources; hovering lists the errors. - tray: notify() shows a balloon tip from any thread (queued on the tray window, NIF_INFO). app.py grows an alert monitor: every 5 s it diffs the current bad states (fan failsafes/control errors, AI backend errors, failing sensor sources) against the last look and balloons only what is new. The first look is the baseline: problems that predate the tray icon stay quiet. - Tests: test_telemetry.py (5) and test_alerts.py (7); README updated.
This commit is contained in:
1 parent
b2da2213b7
commit
ba39016d52
7 files changed
+292
-10
No files matched your search
@@ -50,7 +50,7 @@ class Telemetry:
|
||||
self._history: collections.deque[tuple] = collections.deque(maxlen=int(HISTORY_SECONDS / interval))
|
||||
self._listeners: list[Callable[[Sample], None]] = []
|
||||
self._seq = 0
|
||||
self._last_failure: dict[str, float] = {}
|
||||
self._failures: dict[str, tuple[float, str]] = {} # source -> (monotonic, message) of its latest failed read
|
||||
|
||||
def subscribe(self, listener: Callable[[Sample], None]) -> None:
|
||||
self._listeners.append(listener)
|
||||
@@ -66,13 +66,23 @@ class Telemetry:
|
||||
|
||||
def _source(self, name: str, read: Callable, fallback, *args):
|
||||
try:
|
||||
return read(*args)
|
||||
result = read(*args)
|
||||
except Exception as e:
|
||||
# The loop retries every second, so log each failing source at most once a minute.
|
||||
if time.monotonic() - self._last_failure.get(name, -1e9) >= 60:
|
||||
self._last_failure[name] = time.monotonic()
|
||||
now = time.monotonic()
|
||||
last = self._failures.get(name)
|
||||
if last is None or now - last[0] >= 60:
|
||||
log.warning("%s read failed; continuing without it: %s", name, e, exc_info=True)
|
||||
self._failures[name] = (now, f"{type(e).__name__}: {e}")
|
||||
return fallback
|
||||
self._failures.pop(name, None) # reading again: healthy
|
||||
return result
|
||||
|
||||
def health(self) -> dict[str, dict]:
|
||||
"""Sources whose latest read failed: name -> {"error", "age_s"}. Empty while every source reads."""
|
||||
now = time.monotonic()
|
||||
return {name: {"error": message, "age_s": round(now - when, 1)}
|
||||
for name, (when, message) in self._failures.items()}
|
||||
|
||||
def run(self, stop: threading.Event) -> None:
|
||||
while not stop.is_set():
|
||||
@@ -115,9 +125,10 @@ class Telemetry:
|
||||
def snapshot(self) -> dict:
|
||||
s = self.latest
|
||||
if s is None:
|
||||
return {"seq": 0}
|
||||
return {"seq": 0, "health": self.health()}
|
||||
return {
|
||||
"seq": s.seq, "t": s.t,
|
||||
"health": self.health(),
|
||||
"cpu": {"temp": _r(s.cpu.temp), "load": _r(s.cpu.load), "clock": _r(s.cpu.clock, 0), "power": _r(s.cpu.power)},
|
||||
"gpu": {"temp": _r(s.gpu.temp), "load": _r(s.gpu.load), "clock": _r(s.gpu.clock, 0), "power": _r(s.gpu.power),
|
||||
"vram_used": None if s.vram is None else s.vram[0],
|
||||
|
||||
Reference in new issue
Block a user