You are a senior engineer 1. Do NOT change or break any existing logic or functionality.…
- User
You are a senior engineer
- Do NOT change or break any existing logic or functionality.
- Do NOT introduce any new libraries, imports, or frameworks — use only what is already present in the code.
- Improve the visual layout, styling, responsiveness, and accessibility using best practices.
- Refactor only if it improves readability and maintainability — without side effects.
- Keep all component/file names the same.
Here is the code:
from fastapi import APIRouter, HTTPException, Depends from fastapi.responses import JSONResponse from typing import Dict, Any, List from pydantic import BaseModel from datetime import datetime import psutil import asyncio from sqlalchemy.orm import Session from ..services.websocket_manager import websocket_manager from ..agents.base_agent import BaseAgent from ..database import get_db from ..models.health_check import DBHealthCheck import os import sys
router = APIRouter()
class HealthStatus(BaseModel): """System health status model""" status: str timestamp: datetime uptime: float memory_usage: Dict[str, float] cpu_usage: float active_sessions: int llm_status: Dict[str, str] version: str = "2.0.0"
class ComponentStatus(BaseModel): """Individual component status""" name: str status: str last_check: datetime details: Dict[str, Any] = {}
@router.get("/health", response_model=HealthStatus) async def get_health_status(): """ Get comprehensive system health status
Returns detailed information about system performance, active sessions, and component status. """ try: # Get system metrics memory = psutil.virtual_memory() cpu_percent = psutil.cpu_percent(interval=1) # Get active sessions count active_sessions = len(websocket_manager.active_connections) # Check LLM status llm_status = await _check_llm_status() # Calculate uptime (simplified) uptime = psutil.boot_time() current_time = datetime.now().timestamp() uptime_seconds = current_time - uptime health_status = HealthStatus( status="healthy" if cpu_percent < 80 and memory.percent < 85 else "warning", timestamp=datetime.now(), uptime=uptime_seconds, memory_usage={ "total": memory.total / (1024**3), # GB "available": memory.available / (1024**3), # GB "percent": memory.percent, "used": memory.used / (1024**3) # GB }, cpu_usage=cpu_percent, active_sessions=active_sessions, llm_status=llm_status ) return health_status except Exception as e: raise HTTPException( status_code=500, detail={ "error": "Failed to get health status", "message": str(e), "type": "health_check_error" } )@router.get("/health/detailed") async def get_detailed_health(): """ Get detailed health information for all components
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.