snapshot: summarize namespaces
This commit is contained in:
parent
b58a1138b3
commit
e35f7714c3
@ -73,6 +73,7 @@ def build_summary(snapshot: dict[str, Any] | None) -> dict[str, Any]:
|
||||
summary.update(_build_nodes(snapshot))
|
||||
summary.update(_build_hardware(nodes_detail))
|
||||
summary.update(_build_pods(metrics))
|
||||
summary.update(_build_namespace_pods(snapshot))
|
||||
summary.update(_build_postgres(metrics))
|
||||
summary.update(_build_hottest(metrics))
|
||||
summary.update(_build_workloads(snapshot))
|
||||
@ -129,6 +130,13 @@ def _build_pods(metrics: dict[str, Any]) -> dict[str, Any]:
|
||||
return {"pods": pods}
|
||||
|
||||
|
||||
def _build_namespace_pods(snapshot: dict[str, Any]) -> dict[str, Any]:
|
||||
namespaces = snapshot.get("namespace_pods")
|
||||
if not isinstance(namespaces, list) or not namespaces:
|
||||
return {}
|
||||
return {"namespace_pods": namespaces}
|
||||
|
||||
|
||||
def _build_postgres(metrics: dict[str, Any]) -> dict[str, Any]:
|
||||
postgres = metrics.get("postgres_connections") if isinstance(metrics.get("postgres_connections"), dict) else {}
|
||||
if not postgres:
|
||||
@ -261,6 +269,29 @@ def _append_pods(lines: list[str], summary: dict[str, Any]) -> None:
|
||||
)
|
||||
|
||||
|
||||
def _append_namespace_pods(lines: list[str], summary: dict[str, Any]) -> None:
|
||||
namespaces = summary.get("namespace_pods")
|
||||
if not isinstance(namespaces, list) or not namespaces:
|
||||
return
|
||||
top = sorted(
|
||||
(item for item in namespaces if isinstance(item, dict)),
|
||||
key=lambda item: (-int(item.get("pods_total") or 0), item.get("namespace") or ""),
|
||||
)[:8]
|
||||
parts = []
|
||||
for item in top:
|
||||
name = item.get("namespace")
|
||||
total = item.get("pods_total")
|
||||
running = item.get("pods_running")
|
||||
if not name:
|
||||
continue
|
||||
label = f"{name}={total}"
|
||||
if running is not None:
|
||||
label = f"{label} (running={running})"
|
||||
parts.append(label)
|
||||
if parts:
|
||||
lines.append("namespaces_top: " + "; ".join(parts))
|
||||
|
||||
|
||||
def _append_restarts(lines: list[str], summary: dict[str, Any]) -> None:
|
||||
metrics = summary.get("metrics") if isinstance(summary.get("metrics"), dict) else {}
|
||||
top_restarts = metrics.get("top_restarts_1h") or []
|
||||
@ -371,6 +402,7 @@ def summary_text(snapshot: dict[str, Any] | None) -> str:
|
||||
_append_nodes(lines, summary)
|
||||
_append_hardware(lines, summary)
|
||||
_append_pods(lines, summary)
|
||||
_append_namespace_pods(lines, summary)
|
||||
_append_restarts(lines, summary)
|
||||
_append_postgres(lines, summary)
|
||||
_append_hottest(lines, summary)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user