3053058cdf
Co-authored-by: Cursor <cursoragent@cursor.com>
31 lines
1.0 KiB
Python
31 lines
1.0 KiB
Python
from fastapi import APIRouter, Depends
|
|
from pydantic import BaseModel, Field
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.auth.jwt_auth import get_current_user
|
|
from app.database import get_db
|
|
from app.services.system_stats import collect_system_stats
|
|
from app.services.ui_settings import get_effective_ui_settings
|
|
|
|
router = APIRouter(prefix="/system", tags=["system"])
|
|
|
|
|
|
class SystemStatsResponse(BaseModel):
|
|
visible: bool = Field(description="Показывать блок в боковой панели (глобальная настройка)")
|
|
collected_at: str
|
|
cpu_percent: float | None = None
|
|
memory: dict | None = None
|
|
disk: dict | None = None
|
|
database: dict
|
|
app: dict
|
|
|
|
|
|
@router.get("/stats", response_model=SystemStatsResponse)
|
|
def get_system_stats(
|
|
db: Session = Depends(get_db),
|
|
_user=Depends(get_current_user),
|
|
) -> SystemStatsResponse:
|
|
ui = get_effective_ui_settings(db)
|
|
payload = collect_system_stats(db)
|
|
return SystemStatsResponse(visible=ui.show_sidebar_system_stats, **payload)
|