Skip to content

Commit 9ac65bc

Browse files
authored
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 ualex73#184
1 parent 854c5eb commit 9ac65bc

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

custom_components/monitor_docker/helpers.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,10 +1145,11 @@ async def _run_container_stats(self) -> None:
11451145
cache = 0
11461146
# https://docs.docker.com/engine/reference/commandline/stats/
11471147
# Version is 19.04 or higher, don't use "cache"
1148-
if "total_inactive_file" in raw["memory_stats"]["stats"]:
1149-
cache = raw["memory_stats"]["stats"]["total_inactive_file"]
1150-
elif "inactive_file" in raw["memory_stats"]["stats"]:
1151-
cache = raw["memory_stats"]["stats"]["inactive_file"]
1148+
if "stats" in raw["memory_stats"]:
1149+
if "total_inactive_file" in raw["memory_stats"]["stats"]:
1150+
cache = raw["memory_stats"]["stats"]["total_inactive_file"]
1151+
elif "inactive_file" in raw["memory_stats"]["stats"]:
1152+
cache = raw["memory_stats"]["stats"]["inactive_file"]
11521153

11531154
memory_stats["usage"] = toMB(
11541155
raw["memory_stats"]["usage"] - cache,

0 commit comments

Comments
 (0)