snapshot: refine longhorn health
This commit is contained in:
parent
a6062be60e
commit
d4a632d2e4
@ -1068,7 +1068,10 @@ def _summarize_longhorn_volumes(payload: dict[str, Any]) -> dict[str, Any]:
|
|||||||
return {}
|
return {}
|
||||||
by_state: dict[str, int] = {}
|
by_state: dict[str, int] = {}
|
||||||
by_robustness: dict[str, int] = {}
|
by_robustness: dict[str, int] = {}
|
||||||
unhealthy: list[dict[str, Any]] = []
|
degraded: list[dict[str, Any]] = []
|
||||||
|
attached_count = 0
|
||||||
|
detached_count = 0
|
||||||
|
degraded_count = 0
|
||||||
for volume in items:
|
for volume in items:
|
||||||
metadata = volume.get("metadata") if isinstance(volume.get("metadata"), dict) else {}
|
metadata = volume.get("metadata") if isinstance(volume.get("metadata"), dict) else {}
|
||||||
status = volume.get("status") if isinstance(volume.get("status"), dict) else {}
|
status = volume.get("status") if isinstance(volume.get("status"), dict) else {}
|
||||||
@ -1080,10 +1083,17 @@ def _summarize_longhorn_volumes(payload: dict[str, Any]) -> dict[str, Any]:
|
|||||||
robustness = (
|
robustness = (
|
||||||
status.get("robustness") if isinstance(status.get("robustness"), str) else "unknown"
|
status.get("robustness") if isinstance(status.get("robustness"), str) else "unknown"
|
||||||
)
|
)
|
||||||
|
state_lower = state.lower()
|
||||||
|
robustness_lower = robustness.lower()
|
||||||
by_state[state] = by_state.get(state, 0) + 1
|
by_state[state] = by_state.get(state, 0) + 1
|
||||||
by_robustness[robustness] = by_robustness.get(robustness, 0) + 1
|
by_robustness[robustness] = by_robustness.get(robustness, 0) + 1
|
||||||
if state.lower() != "attached" or robustness.lower() != "healthy":
|
if state_lower == "attached":
|
||||||
unhealthy.append(
|
attached_count += 1
|
||||||
|
elif state_lower == "detached":
|
||||||
|
detached_count += 1
|
||||||
|
if robustness_lower in {"degraded", "faulted"}:
|
||||||
|
degraded_count += 1
|
||||||
|
degraded.append(
|
||||||
{
|
{
|
||||||
"name": name,
|
"name": name,
|
||||||
"state": state,
|
"state": state,
|
||||||
@ -1092,13 +1102,15 @@ def _summarize_longhorn_volumes(payload: dict[str, Any]) -> dict[str, Any]:
|
|||||||
"actual_size": status.get("actualSize"),
|
"actual_size": status.get("actualSize"),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
unhealthy.sort(key=lambda item: item.get("name") or "")
|
degraded.sort(key=lambda item: item.get("name") or "")
|
||||||
return {
|
return {
|
||||||
"total": len(items),
|
"total": len(items),
|
||||||
"by_state": by_state,
|
"by_state": by_state,
|
||||||
"by_robustness": by_robustness,
|
"by_robustness": by_robustness,
|
||||||
"unhealthy": unhealthy,
|
"attached_count": attached_count,
|
||||||
"unhealthy_count": len(unhealthy),
|
"detached_count": detached_count,
|
||||||
|
"degraded": degraded,
|
||||||
|
"degraded_count": degraded_count,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user