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
+16
-4
@@ -197,6 +197,11 @@ class Kurgan:
|
||||
self.telemetry = Telemetry(hw["cpu"] if hw else CpuSensors(),
|
||||
hw["gpu"] if hw else GpuSensors(load_source=args.gpu_load),
|
||||
self.system, args.interval)
|
||||
self.recorder = None
|
||||
if not args.demo: # simulated samples must not mix into the real records
|
||||
from kurgan.telemetry.record import Recorder
|
||||
self.recorder = Recorder(paths.DATA_DIR)
|
||||
self.telemetry.subscribe(self.recorder.on_sample)
|
||||
self.display = None if (args.no_lcd or hw) else DisplayService(
|
||||
DashboardRenderer(self.theme, rotate180=args.rotate180), self.telemetry, args.brightness)
|
||||
|
||||
@@ -295,12 +300,10 @@ class Kurgan:
|
||||
known = states
|
||||
|
||||
def _start_tray(self) -> None:
|
||||
from kurgan.tray import TrayIcon, make_icon
|
||||
from kurgan.tray import ICON_PATH, TrayIcon
|
||||
|
||||
try:
|
||||
icon = make_icon(os.path.join(paths.DATA_DIR, "tray.ico"),
|
||||
[self.theme.other_color, self.theme.cpu_color, self.theme.gpu_color])
|
||||
self.tray = TrayIcon(APP_NAME, icon, on_exit=self.stop.set,
|
||||
self.tray = TrayIcon(APP_NAME, ICON_PATH, on_exit=self.stop.set,
|
||||
on_open=self.open_ui if self.web else None, status_lines=self.tray_lines)
|
||||
self.tray.start()
|
||||
except Exception:
|
||||
@@ -331,6 +334,8 @@ class Kurgan:
|
||||
deadline = time.monotonic() + 60 # Strata may take up to ~45 s to shut down cleanly
|
||||
for thread in self._threads:
|
||||
thread.join(max(0.1, deadline - time.monotonic()))
|
||||
if self.recorder is not None:
|
||||
self.recorder.close() # after the telemetry thread has stopped writing
|
||||
self.lighting.join()
|
||||
self.system.fans.close()
|
||||
|
||||
@@ -368,6 +373,13 @@ class Kurgan:
|
||||
return {**self.telemetry.history(),
|
||||
"fans": {"series": ("t", "gpu_duty", "cpu_duty", "top_duty"), "rows": list(self.fan_history)}}
|
||||
|
||||
def records(self, days: int) -> dict:
|
||||
from kurgan.telemetry.record import RETENTION_DAYS, load
|
||||
|
||||
if not isinstance(days, int) or not 1 <= days <= RETENTION_DAYS:
|
||||
raise ValueError(f"days must be a whole number from 1 to {RETENTION_DAYS}")
|
||||
return load(paths.DATA_DIR, days)
|
||||
|
||||
def set_lighting(self, zone: str, mode: str) -> None:
|
||||
self.lighting.set_mode(zone, mode)
|
||||
|
||||
|
||||
Reference in new issue
Block a user