dadabd7954
- Add system metrics endpoint (CPU load, memory, swap, network traffic) - Collect metrics from /proc and /sys (no subprocess required) - Overhaul dashboard to pull from per-subsystem models - Remove deprecated /status/all monolithic endpoint - Improve networkd import to handle optional priority prefix - Fix CSS duplicate .grid-4 rule and unused dashboard imports
36 lines
979 B
Python
36 lines
979 B
Python
"""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
|