Long-term telemetry: hourly rollups in JSONL, a range selector in the UI
- telemetry/record.py: a Recorder subscribed to Telemetry keeps min/avg/max per metric for the current hour and appends each finished hour as one JSON line to records-YYYY-MM.jsonl in the data dir (~400 days kept; whole months older than that are pruned on start). Best effort by design: a failing disk logs once and stops recording; nothing else notices. load() merges lines per hour (a restart re-writes the current hour; torn last lines are skipped). - app.py: the recorder runs unless --demo (simulated samples must not mix into real records) and flushes the open hour in close(), after the telemetry thread has stopped. records(days) validates 1..400. - Web: GET /api/records?days=N (bad values answer 400 with the reason). - UI: a range selector above the power/temperature charts switches them between the live 10 minutes and hourly averages for 24 h / 7 d / 30 d / 1 y; the chart window, tick labels (min/h/d), tooltips and table captions adapt to the span. Live samples keep accumulating behind a long-range view, so switching back is instant. - Tests: test_record.py (5) and a /api/records case in test_web.py; README updated (API table, System section, layout).
This commit is contained in:
1 parent
ba39016d52
commit
f717f7a82f
8 files changed
+371
-18
No files matched your search
@@ -35,6 +35,12 @@ class FakeApp:
|
||||
def ai_model(self, action):
|
||||
self.calls.append(("model", action))
|
||||
|
||||
def records(self, days):
|
||||
self.calls.append(("records", days))
|
||||
if not 1 <= days <= 400:
|
||||
raise ValueError("days must be a whole number from 1 to 400")
|
||||
return {"metrics": [], "rows": [], "days": days}
|
||||
|
||||
|
||||
def free_port() -> int:
|
||||
with socket.socket() as s:
|
||||
@@ -127,6 +133,19 @@ class WebServerTest(unittest.TestCase):
|
||||
self.request("POST", "/api/ai/active", {"backend": "strata", "variant": "iq3"})
|
||||
self.assertEqual(self.app.calls, [("ai", None, None), ("ai", "strata", "iq3")])
|
||||
|
||||
def test_records_serves_the_long_term_rollups(self):
|
||||
status, _, body = self.request("GET", "/api/records") # no days: the default week
|
||||
self.assertEqual((status, json.loads(body)["days"]), (200, 7))
|
||||
status, _, body = self.request("GET", "/api/records?days=30")
|
||||
self.assertEqual((status, json.loads(body)["days"]), (200, 30))
|
||||
self.assertEqual(self.app.calls, [("records", 7), ("records", 30)])
|
||||
for path in ("/api/records?days=abc", "/api/records?days=0", "/api/records?days=-3",
|
||||
"/api/records?days=401", "/api/records?days=1.5"):
|
||||
with self.subTest(path=path):
|
||||
status, _, raw = self.request("GET", path)
|
||||
self.assertEqual(status, 400)
|
||||
self.assertIn("whole number", json.loads(raw)["error"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user