"""System metrics handler. Returns CPU load, memory usage, and per-interface network traffic stats. """ from __future__ import annotations import logging from typing import Any from daemon.iface import GET_SYSTEM_METRICS from daemon.server import registry from lib.state import state as state_store logger = logging.getLogger(__name__) @registry.register(GET_SYSTEM_METRICS) def system_metrics(_request: Any, _body: Any) -> dict[str, Any]: """Return system-wide metrics. Reads from pre-collected state (CPU load, memory, network traffic). Returns: Dict with load, memory, swap, and traffic data. """ sys_state = state_store.get("system") if sys_state is None: return { "load": {"load1": 0.0, "load5": 0.0, "load15": 0.0}, "memory": {"total": 0, "available": 0, "used": 0, "used_pct": 0}, "swap": {"total": 0, "used": 0, "used_pct": 0}, "traffic": {}, } return sys_state