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
@@ -3,6 +3,7 @@
|
||||
GET / the UI (static/index.html)
|
||||
GET /api/state everything live, polled by the UI once a second
|
||||
GET /api/history the last 10 minutes of telemetry (fetched once; the UI appends from /api/state)
|
||||
GET /api/records?days=N hourly min/avg/max rollups for the last N days (long-term telemetry)
|
||||
GET /api/config fan profiles, lighting zones and AI backends (static)
|
||||
POST /api/lighting {"zone": "case_fans"|"memory"|"gpu", "mode": "off"|...}
|
||||
POST /api/cooling/profile {"profile": "quiet"|"balanced"|"performance"|"full"}
|
||||
@@ -26,6 +27,7 @@ import mimetypes
|
||||
import os
|
||||
import threading
|
||||
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
|
||||
from urllib.parse import parse_qs
|
||||
|
||||
from kurgan.web import proxy
|
||||
|
||||
@@ -105,12 +107,15 @@ def make_handler(app, port: int):
|
||||
def do_GET(self) -> None:
|
||||
if self._proxied() or not self._guard():
|
||||
return
|
||||
path = self.path.split("?", 1)[0]
|
||||
path, _, query = self.path.partition("?")
|
||||
try:
|
||||
if path == "/api/state":
|
||||
self._json(200, app.state())
|
||||
elif path == "/api/history":
|
||||
self._json(200, app.history())
|
||||
elif path == "/api/records":
|
||||
raw = parse_qs(query).get("days", ["7"])[0]
|
||||
self._json(200, app.records(int(raw) if raw.isdigit() else -1))
|
||||
elif path == "/api/config":
|
||||
self._json(200, app.config())
|
||||
elif path in ("/", "/index.html"):
|
||||
@@ -119,6 +124,8 @@ def make_handler(app, port: int):
|
||||
self._static(path[len("/static/"):])
|
||||
else:
|
||||
self._json(404, {"error": "not found"})
|
||||
except ValueError as e:
|
||||
self._json(400, {"error": str(e)})
|
||||
except Exception:
|
||||
log.exception("GET %s failed", path)
|
||||
self._json(500, {"error": "internal error; see kurgan.log"})
|
||||
|
||||
Reference in new issue
Block a user