fix: watcher manager now displays "heard from" status, instead of unit status. Refreshes ever 60 mins, if havent heard from in >60 mins display missing.
This commit is contained in:
@@ -31,11 +31,15 @@ router = APIRouter(tags=["admin"])
|
|||||||
def _agent_to_dict(agent: WatcherAgent) -> dict:
|
def _agent_to_dict(agent: WatcherAgent) -> dict:
|
||||||
last_seen = agent.last_seen
|
last_seen = agent.last_seen
|
||||||
if last_seen:
|
if last_seen:
|
||||||
# Compute age in minutes (last_seen stored as UTC naive)
|
|
||||||
now_utc = datetime.utcnow()
|
now_utc = datetime.utcnow()
|
||||||
age_minutes = int((now_utc - last_seen).total_seconds() // 60)
|
age_minutes = int((now_utc - last_seen).total_seconds() // 60)
|
||||||
|
if age_minutes > 60:
|
||||||
|
status = "missing"
|
||||||
|
else:
|
||||||
|
status = "ok"
|
||||||
else:
|
else:
|
||||||
age_minutes = None
|
age_minutes = None
|
||||||
|
status = "missing"
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"id": agent.id,
|
"id": agent.id,
|
||||||
@@ -43,7 +47,7 @@ def _agent_to_dict(agent: WatcherAgent) -> dict:
|
|||||||
"version": agent.version,
|
"version": agent.version,
|
||||||
"last_seen": last_seen.isoformat() if last_seen else None,
|
"last_seen": last_seen.isoformat() if last_seen else None,
|
||||||
"age_minutes": age_minutes,
|
"age_minutes": age_minutes,
|
||||||
"status": agent.status,
|
"status": status,
|
||||||
"ip_address": agent.ip_address,
|
"ip_address": agent.ip_address,
|
||||||
"log_tail": agent.log_tail,
|
"log_tail": agent.log_tail,
|
||||||
"update_pending": bool(agent.update_pending),
|
"update_pending": bool(agent.update_pending),
|
||||||
|
|||||||
@@ -216,20 +216,9 @@ async def series3_heartbeat(request: Request, db: Session = Depends(get_db)):
|
|||||||
|
|
||||||
results.append({"unit": uid, "status": status})
|
results.append({"unit": uid, "status": status})
|
||||||
|
|
||||||
# Determine overall worst status for the watcher agent row
|
|
||||||
statuses = [r["status"] for r in results]
|
|
||||||
if "Missing" in statuses:
|
|
||||||
agent_status = "missing"
|
|
||||||
elif "Pending" in statuses:
|
|
||||||
agent_status = "pending"
|
|
||||||
elif statuses:
|
|
||||||
agent_status = "ok"
|
|
||||||
else:
|
|
||||||
agent_status = "unknown"
|
|
||||||
|
|
||||||
if source:
|
if source:
|
||||||
_upsert_watcher_agent(db, source, "series3_watcher", version,
|
_upsert_watcher_agent(db, source, "series3_watcher", version,
|
||||||
client_ip, log_tail_str, agent_status)
|
client_ip, log_tail_str, "ok")
|
||||||
|
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
@@ -340,20 +329,9 @@ async def series4_heartbeat(request: Request, db: Session = Depends(get_db)):
|
|||||||
|
|
||||||
results.append({"unit": uid, "status": status})
|
results.append({"unit": uid, "status": status})
|
||||||
|
|
||||||
# Determine overall worst status for the watcher agent row
|
|
||||||
statuses = [r["status"] for r in results]
|
|
||||||
if any(s.lower() == "stale" for s in statuses):
|
|
||||||
agent_status = "missing"
|
|
||||||
elif any(s.lower() == "late" for s in statuses):
|
|
||||||
agent_status = "pending"
|
|
||||||
elif statuses:
|
|
||||||
agent_status = "ok"
|
|
||||||
else:
|
|
||||||
agent_status = "unknown"
|
|
||||||
|
|
||||||
if source:
|
if source:
|
||||||
_upsert_watcher_agent(db, source, "series4_watcher", version,
|
_upsert_watcher_agent(db, source, "series4_watcher", version,
|
||||||
client_ip, log_tail_str, agent_status)
|
client_ip, log_tail_str, "ok")
|
||||||
|
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user