feat: add system info to hardware stats sensor

This commit is contained in:
yellowcooln
2026-06-24 16:23:50 -04:00
parent b4b44831b0
commit 44a2d2f72f
2 changed files with 45 additions and 1 deletions
+28 -1
View File
@@ -12,6 +12,7 @@ except ImportError:
psutil = None
import logging
import platform
import time
logger = logging.getLogger("HardwareStats")
@@ -57,6 +58,7 @@ class HardwareStatsCollector:
# System boot time
boot_time = psutil.boot_time()
system_uptime = now - boot_time
system_info = self._get_system_info()
# Temperature (if available)
temperatures = {}
@@ -96,7 +98,13 @@ class HardwareStatsCollector:
"packets_sent": net_io.packets_sent,
"packets_recv": net_io.packets_recv,
},
"system": {"uptime": system_uptime, "boot_time": boot_time},
"system": {
"uptime": system_uptime,
"boot_time": boot_time,
"os": system_info["os"],
"kernel": system_info["kernel"],
"arch": system_info["arch"],
},
}
# Add temperatures if available
@@ -109,6 +117,25 @@ class HardwareStatsCollector:
logger.error(f"Error collecting hardware stats: {e}")
return {"error": str(e)}
@staticmethod
def _get_system_info(os_release_path="/etc/os-release"):
os_name = None
try:
with open(os_release_path, "r", encoding="utf-8") as f:
for line in f:
key, sep, value = line.partition("=")
if sep and key == "PRETTY_NAME":
os_name = value.strip().strip('"')
break
except OSError:
os_name = None
return {
"os": os_name or platform.system(),
"kernel": platform.release(),
"arch": platform.machine(),
}
def get_processes_summary(self, limit=10):
"""
Get top processes by CPU and memory usage.
+17
View File
@@ -160,6 +160,23 @@ def test_hardware_stats_sensor_reads_from_collector(monkeypatch):
assert reading["data"] == {"cpu": {"usage_percent": 42.0}}
def test_hardware_stats_collector_reads_os_kernel_and_arch(tmp_path, monkeypatch):
import repeater.data_acquisition.hardware_stats as hardware_stats_module
os_release = tmp_path / "os-release"
os_release.write_text('NAME="Debian GNU/Linux"\nPRETTY_NAME="Debian GNU/Linux 12"\n')
monkeypatch.setattr(hardware_stats_module.platform, "release", lambda: "6.8.0-test")
monkeypatch.setattr(hardware_stats_module.platform, "machine", lambda: "aarch64")
info = hardware_stats_module.HardwareStatsCollector._get_system_info(str(os_release))
assert info == {
"os": "Debian GNU/Linux 12",
"kernel": "6.8.0-test",
"arch": "aarch64",
}
def test_pymc_modem_sensor_reads_modem_stats(monkeypatch):
class _Response:
status = 200