feat: implement Swapper metrics collection and UI

This commit is contained in:
Apple
2025-11-30 15:12:49 -08:00
parent 5b5160ad8b
commit fd814b2059
11 changed files with 1224 additions and 4543 deletions

View File

@@ -4057,6 +4057,52 @@ async def get_node_self_healing_status(node_id: str):
)
@router.get("/internal/node/{node_id}/swapper", response_model=NodeSwapperDetail)
async def get_node_swapper_detail(node_id: str):
"""
Get detailed Swapper Service status for a node.
Used by Node Cabinet to show loaded models and health.
"""
try:
# Fetch from node_cache
metrics = await repo_city.get_node_metrics(node_id)
if not metrics:
raise HTTPException(status_code=404, detail="Node not found")
# Parse swapper state (stored as JSONB)
state = metrics.get("swapper_state") or {}
models_data = state.get("models", [])
models = [
SwapperModel(
name=m.get("name", "unknown"),
loaded=m.get("loaded", False),
type=m.get("type"),
vram_gb=m.get("vram_gb")
)
for m in models_data
]
return NodeSwapperDetail(
node_id=node_id,
healthy=metrics.get("swapper_healthy", False),
models_loaded=metrics.get("swapper_models_loaded", 0),
models_total=metrics.get("swapper_models_total", 0),
models=models
)
except HTTPException:
raise
except Exception as e:
logger.error(f"Failed to get swapper detail for {node_id}: {e}")
return NodeSwapperDetail(
node_id=node_id,
healthy=False,
models_loaded=0,
models_total=0,
models=[]
)
@router.get("/internal/node/{node_id}/directory-check")
async def check_node_in_directory(node_id: str):
"""