From 9ac65bcdd522931dbe900b05e99c50af851bf5e6 Mon Sep 17 00:00:00 2001 From: Danilo Luvizotto Date: Mon, 17 Feb 2025 20:42:17 -0300 Subject: [PATCH] Fix memory calculations when "stats" key is not present in "memory_stats" "stats" is not present in "memory_stats" when using podman instead of docker, breaking the memory calculations. Everything else works fine. this PR fixes https://github.com/ualex73/monitor_docker/issues/184 --- custom_components/monitor_docker/helpers.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/custom_components/monitor_docker/helpers.py b/custom_components/monitor_docker/helpers.py index 1e1e230..fc719d9 100644 --- a/custom_components/monitor_docker/helpers.py +++ b/custom_components/monitor_docker/helpers.py @@ -1145,10 +1145,11 @@ async def _run_container_stats(self) -> None: cache = 0 # https://docs.docker.com/engine/reference/commandline/stats/ # Version is 19.04 or higher, don't use "cache" - if "total_inactive_file" in raw["memory_stats"]["stats"]: - cache = raw["memory_stats"]["stats"]["total_inactive_file"] - elif "inactive_file" in raw["memory_stats"]["stats"]: - cache = raw["memory_stats"]["stats"]["inactive_file"] + if "stats" in raw["memory_stats"]: + if "total_inactive_file" in raw["memory_stats"]["stats"]: + cache = raw["memory_stats"]["stats"]["total_inactive_file"] + elif "inactive_file" in raw["memory_stats"]["stats"]: + cache = raw["memory_stats"]["stats"]["inactive_file"] memory_stats["usage"] = toMB( raw["memory_stats"]["usage"] - cache,