52 lines
1.4 KiB
Python
52 lines
1.4 KiB
Python
# Count agents from database
|
|
agent_count = await pool.fetchval("""
|
|
SELECT COUNT(*)
|
|
FROM agents
|
|
WHERE (node_id = $1 OR node_id IS NULL)
|
|
AND COALESCE(is_archived, false) = false
|
|
AND COALESCE(is_test, false) = false
|
|
AND deleted_at IS NULL
|
|
""", node_id)
|
|
|
|
result = dict(row)
|
|
result["agents_total"] = agent_count or row["agent_count_router"]
|
|
|
|
# Add GPU info for compatibility
|
|
if row["gpu_model"]:
|
|
result["gpu_info"] = f"{row['gpu_model']} ({row['gpu_vram_total']}MB)"
|
|
else:
|
|
result["gpu_info"] = None
|
|
|
|
return result
|
|
|
|
|
|
async def get_node_metrics(node_id: str) -> Optional[Dict[str, Any]]:
|
|
"""
|
|
Отримати розширені метрики ноди (включаючи Swapper).
|
|
"""
|
|
pool = await get_pool()
|
|
|
|
row = await pool.fetchrow("""
|
|
SELECT
|
|
node_id,
|
|
swapper_healthy,
|
|
swapper_models_loaded,
|
|
swapper_models_total,
|
|
swapper_state
|
|
FROM node_cache
|
|
WHERE node_id = $1
|
|
""", node_id)
|
|
|
|
if not row:
|
|
return None
|
|
|
|
result = dict(row)
|
|
if result.get("swapper_state"):
|
|
try:
|
|
if isinstance(result["swapper_state"], str):
|
|
result["swapper_state"] = json.loads(result["swapper_state"])
|
|
except Exception:
|
|
result["swapper_state"] = {}
|
|
|
|
return result
|