change resolution

This commit is contained in:
Iñigo Etxaniz
2026-11-09 21:42:10 +00:00
parent e00f375fd0
commit 1080045b9d
+7 -2
View File
@@ -14,6 +14,7 @@ MINUTE_MS = 60000
HOUR_MS = 60 * MINUTE_MS
LOOKBACK_MS = 60 * 24 * HOUR_MS
MATCH_MS = 2 * MINUTE_MS
MINUTE_RESOLUTION_LIMIT_MS = 7 * 24 * HOUR_MS
EXIT_RETRYABLE = 1
EXIT_PERMANENT = 2
REFUSED_STATUS_MIN = 400
@@ -156,14 +157,18 @@ def mean_max(series, start_ms, end_ms):
def coverage(series, start_ms, end_ms):
total = max(1, (end_ms - start_ms) // MINUTE_MS)
total = max(1, (end_ms - start_ms) // series["stepMs"])
present = sum(1 for t, _ in samples(series) if start_ms <= t < end_ms)
return min(1.0, present / total)
def pick_resolution(duration_ms):
return "1min" if duration_ms <= MINUTE_RESOLUTION_LIMIT_MS else "1hr"
def build_row(host, start_ms, end_ms):
cpu, ram, disk = f"{host}-cpu", f"{host}-ram", f"{host}-disk"
history = read_history([cpu, ram, disk], start_ms, end_ms, "1min")
history = read_history([cpu, ram, disk], start_ms, end_ms, pick_resolution(end_ms - start_ms))
row = {"start_time": start_ms, "end_time": end_ms, "duration_s": (end_ms - start_ms) // 1000}
for prefix, signal in (("cpu", cpu), ("ram", ram), ("disk", disk)):
row[f"{prefix}_mean"], row[f"{prefix}_max"] = mean_max(history[signal], start_ms, end_ms)