snapshot: add node load and namespace capacity

This commit is contained in:
Brad Stein 2026-01-29 13:05:38 -03:00
parent 3ffcfddb92
commit 9f2ccf4f31

View File

@ -85,14 +85,18 @@ def build_summary(snapshot: dict[str, Any] | None) -> dict[str, Any]:
summary.update(_build_namespace_pods(snapshot)) summary.update(_build_namespace_pods(snapshot))
summary.update(_build_namespace_nodes(snapshot)) summary.update(_build_namespace_nodes(snapshot))
summary.update(_build_node_pods(snapshot)) summary.update(_build_node_pods(snapshot))
summary.update(_build_node_pods_top(metrics))
summary.update(_build_pod_issues(snapshot)) summary.update(_build_pod_issues(snapshot))
summary.update(_build_workload_health(snapshot)) summary.update(_build_workload_health(snapshot))
summary.update(_build_events(snapshot)) summary.update(_build_events(snapshot))
summary.update(_build_event_summary(snapshot))
summary.update(_build_postgres(metrics)) summary.update(_build_postgres(metrics))
summary.update(_build_hottest(metrics)) summary.update(_build_hottest(metrics))
summary.update(_build_pvc(metrics)) summary.update(_build_pvc(metrics))
summary.update(_build_namespace_capacity(metrics))
summary.update(_build_longhorn(snapshot)) summary.update(_build_longhorn(snapshot))
summary.update(_build_root_disk_headroom(metrics)) summary.update(_build_root_disk_headroom(metrics))
summary.update(_build_node_load(metrics))
summary.update(_build_workloads(snapshot)) summary.update(_build_workloads(snapshot))
summary.update(_build_flux(snapshot)) summary.update(_build_flux(snapshot))
return summary return summary
@ -251,6 +255,13 @@ def _build_longhorn(snapshot: dict[str, Any]) -> dict[str, Any]:
return {"longhorn": longhorn} if isinstance(longhorn, dict) and longhorn else {} return {"longhorn": longhorn} if isinstance(longhorn, dict) and longhorn else {}
def _build_node_load(metrics: dict[str, Any]) -> dict[str, Any]:
node_load = metrics.get("node_load")
if not isinstance(node_load, list) or not node_load:
return {}
return {"node_load": node_load}
def _build_pods(metrics: dict[str, Any]) -> dict[str, Any]: def _build_pods(metrics: dict[str, Any]) -> dict[str, Any]:
pods = { pods = {
"running": metrics.get("pods_running"), "running": metrics.get("pods_running"),
@ -300,6 +311,13 @@ def _build_node_pods(snapshot: dict[str, Any]) -> dict[str, Any]:
return {"node_pods": node_pods} return {"node_pods": node_pods}
def _build_node_pods_top(metrics: dict[str, Any]) -> dict[str, Any]:
top = metrics.get("node_pods_top")
if not isinstance(top, list) or not top:
return {}
return {"node_pods_top": top}
def _build_pod_issues(snapshot: dict[str, Any]) -> dict[str, Any]: def _build_pod_issues(snapshot: dict[str, Any]) -> dict[str, Any]:
pod_issues = snapshot.get("pod_issues") pod_issues = snapshot.get("pod_issues")
if not isinstance(pod_issues, dict) or not pod_issues: if not isinstance(pod_issues, dict) or not pod_issues:
@ -332,6 +350,18 @@ def _build_events(snapshot: dict[str, Any]) -> dict[str, Any]:
return {"events": events} return {"events": events}
def _build_event_summary(snapshot: dict[str, Any]) -> dict[str, Any]:
events = snapshot.get("events")
if not isinstance(events, dict) or not events:
return {}
summary = {}
if isinstance(events.get("warnings_top_reason"), dict):
summary["warnings_top_reason"] = events.get("warnings_top_reason")
if events.get("warnings_latest"):
summary["warnings_latest"] = events.get("warnings_latest")
return {"event_summary": summary} if summary else {}
def _build_postgres(metrics: dict[str, Any]) -> dict[str, Any]: def _build_postgres(metrics: dict[str, Any]) -> dict[str, Any]:
postgres = metrics.get("postgres_connections") if isinstance(metrics.get("postgres_connections"), dict) else {} postgres = metrics.get("postgres_connections") if isinstance(metrics.get("postgres_connections"), dict) else {}
if not postgres: if not postgres:
@ -365,6 +395,13 @@ def _build_pvc(metrics: dict[str, Any]) -> dict[str, Any]:
return {"pvc_usage_top": pvc_usage} return {"pvc_usage_top": pvc_usage}
def _build_namespace_capacity(metrics: dict[str, Any]) -> dict[str, Any]:
capacity = metrics.get("namespace_capacity")
if not isinstance(capacity, list) or not capacity:
return {}
return {"namespace_capacity": capacity}
def _build_workloads(snapshot: dict[str, Any]) -> dict[str, Any]: def _build_workloads(snapshot: dict[str, Any]) -> dict[str, Any]:
workloads = snapshot.get("workloads") if isinstance(snapshot.get("workloads"), list) else [] workloads = snapshot.get("workloads") if isinstance(snapshot.get("workloads"), list) else []
return {"workloads": workloads} return {"workloads": workloads}