Hostname aus /etc/hostname des Hosts statt Container-ID, veth-Schnittstellen ausblenden

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
guyg1474andClaude Opus 5.5 committed 2026-10-14 16:04:59 +02:00
1 parent f89ef84aa4
commit 21fbb4ad14
2 files changed
+11 -3

No files matched your search

+9 -2
View File
@@ -205,6 +205,12 @@ def _cpu_mhz() -> float | None:
return round(sum(freqs) / len(freqs)) if freqs else None
def _hostname() -> str | None:
# /proc/sys/kernel/hostname liefert im Container dessen ID (eigener UTS-Namespace),
# daher zuerst die Datei des Hosts
return _read_or(_host_path("/etc/hostname")) or _read_or(f"{HOST_PROC}/sys/kernel/hostname")
def _os_name() -> str | None:
for path in (_host_path("/etc/os-release"), _host_path("/usr/lib/os-release")):
text = _read_or(path)
@@ -242,7 +248,8 @@ def snapshot(prev: dict, cur: dict, interval: int) -> dict:
net, rx_sum, tx_sum = [], 0, 0
for name, (rx, tx) in sorted(cur["net"].items()):
if name == "lo":
# veth*: eine pro Container mit Zufallsnamen – nur Rauschen in der Liste
if name == "lo" or name.startswith("veth"):
continue
p_rx, p_tx = prev["net"].get(name, (rx, tx))
rx_rate, tx_rate = _rate(rx, p_rx, seconds), _rate(tx, p_tx, seconds)
@@ -268,7 +275,7 @@ def snapshot(prev: dict, cur: dict, interval: int) -> dict:
"timestamp": datetime.now().astimezone().isoformat(timespec="seconds"),
"intervalSeconds": interval,
"host": {
"hostname": _read_or(f"{HOST_PROC}/sys/kernel/hostname"),
"hostname": _hostname(),
"os": _os_name(),
"kernel": _read_or(f"{HOST_PROC}/sys/kernel/osrelease"),
"uptimeSeconds": int(uptime),