Handle Docker stats without embedded container names

This commit is contained in:
Artyom
2026-11-06 21:26:45 +03:00
parent 202b985dea
commit bc0b162082
3 changed files with 125 additions and 2 deletions
+9 -1
View File
@@ -76,6 +76,14 @@ class Resources:
raise RuntimeError("cost measurement requires a local Docker socket")
self.path = host[7:]
self.ids = compose("ps", "-q").splitlines()
self.names = dict(
zip(
self.ids,
subprocess.check_output(
["docker", "inspect", "-f", "{{.Name}}", *self.ids], text=True
).splitlines(),
)
)
self.samples = []
self.stop = threading.Event()
self.thread = threading.Thread(target=self.poll)
@@ -90,7 +98,7 @@ class Resources:
rows.append(
{
"id": identity[:12],
"name": data["name"],
"name": self.names[identity],
"cpu_ns": data["cpu_stats"]["cpu_usage"]["total_usage"],
"working_set_bytes": memory["usage"]
- memory.get("stats", {}).get("inactive_file", 0),