"""REST: системная статистика и сводный статус.""" from __future__ import annotations import os from fastapi import APIRouter from ..runtime import runtime from ..services.system import system_stats router = APIRouter(prefix="/api", tags=["system"]) VERSION_FILE = os.environ.get("NVR_VERSION_FILE", "/app/VERSION") def app_version() -> str: try: with open(VERSION_FILE, "r", encoding="utf-8") as fh: return fh.read().strip() except OSError: return "0.0.0" @router.get("/system") async def get_system() -> dict: stats = system_stats(runtime.config) stats["cameras"] = [s.to_dict() for s in runtime.supervisor.statuses()] stats["archive_size_bytes"] = await runtime.db.total_size() stats["version"] = app_version() return stats @router.get("/health") async def health() -> dict: return {"status": "ok"}