A resources timer samples host CPU, RAM, swap and per-session tokens into samples.jsonl; the hub serves them and a Resources view charts them. Committed below the bar on the operator's word 2026-11-12 (no further per-bundle tests, one gate after the merge): the W4 e2e never ran in a real browser. 🎯 Fix: 92 % 💥 Break: 6 % 💸 Cost: 100 % ⏱️ Time: 100 % 🛡️ Security: 100 % 🏆 Score: 86 🚦 Gate: ⛔ break 6 % > 5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
39 lines
1.3 KiB
Python
39 lines
1.3 KiB
Python
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
from .records import epoch, parse_line, read_regular
|
|
|
|
RESOURCES = "resources"
|
|
SAMPLES = "samples.jsonl"
|
|
TOKENS = "tokens.jsonl"
|
|
HOUR = 3600
|
|
FILE_LIMIT = 64 << 20
|
|
|
|
|
|
def rows_between(path: Path, begin: float, end: float, width: float) -> list[dict]:
|
|
try:
|
|
lines = read_regular(path, FILE_LIMIT).splitlines()
|
|
except (OSError, ValueError):
|
|
return []
|
|
found = []
|
|
for row in map(parse_line, lines):
|
|
t = None if row is None else epoch(row.get("t"))
|
|
if t is not None and begin <= t + width and t <= end:
|
|
found.append(row)
|
|
return found
|
|
|
|
|
|
def sampled(folder: Path, span: tuple[float, float]) -> dict:
|
|
"""Args:
|
|
folder: the host sampler's directory, mounted read-only.
|
|
span: (begin, end) of the page's time window in epoch seconds.
|
|
|
|
Returns:
|
|
{"since", "until", "samples", "tokens"}: the rows of samples.jsonl
|
|
within the span and those of tokens.jsonl whose hour overlaps it, as
|
|
the host unit wrote them; the hub reads nothing of the host itself.
|
|
"""
|
|
begin, end = span
|
|
return {"since": begin, "until": end, "samples": rows_between(folder / SAMPLES, begin, end, 0), "tokens": rows_between(folder / TOKENS, begin, end, HOUR)}
|