feat(reporter): add uptime and fleet counters to state snapshot

This commit is contained in:
patrick committed 2026-03-05 20:57:16 -05:00
1 parent 7f323ed78b
commit 3b1e25d5cd
6 files changed
+55 -6

No files matched your search

+28
View File
@@ -3,6 +3,7 @@
import json
import os
import logging
import time
from datetime import datetime
class LocalStateReporter:
@@ -17,6 +18,7 @@ class LocalStateReporter:
):
self.state_file = state_file
self.node_name = node_name
self.started_at_epoch = time.time()
# Ensure the directory is writable
os.makedirs(os.path.dirname(os.path.abspath(self.state_file)), exist_ok=True)
@@ -28,6 +30,12 @@ class LocalStateReporter:
except Exception:
return {}
def _get_int(self, payload, key, default=0):
try:
return int(payload.get(key, default))
except Exception:
return default
def update_status(
self,
is_synced,
@@ -38,6 +46,8 @@ class LocalStateReporter:
metadata_drift_count=0,
last_drift_fingerprint="",
last_heal_result=None,
checks_increment=0,
heal_result=None,
):
"""
Writes the current health snapshot to a JSON file.
@@ -48,6 +58,20 @@ class LocalStateReporter:
if last_heal_result is not None
else previous.get("last_heal_result")
)
if heal_result is not None:
effective_heal_result = heal_result
checks_total = max(0, self._get_int(previous, "checks_total", 0))
checks_total += max(0, int(checks_increment))
heals_total = max(0, self._get_int(previous, "heals_total", 0))
heal_failures_total = max(0, self._get_int(previous, "heal_failures_total", 0))
if heal_result is not None:
heals_total += 1
if heal_result != "success":
heal_failures_total += 1
uptime_seconds = max(0, int(time.time() - self.started_at_epoch))
status_data = {
"node_name": self.node_name,
"last_check": datetime.now().isoformat(),
@@ -60,6 +84,10 @@ class LocalStateReporter:
"metadata_drift_count": metadata_drift_count,
"last_drift_fingerprint": last_drift_fingerprint,
"last_heal_result": effective_heal_result,
"uptime_seconds": uptime_seconds,
"checks_total": checks_total,
"heals_total": heals_total,
"heal_failures_total": heal_failures_total,
}
try: