From 14bc771ba96a444d4c51642c899c5772d1cd7087 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Thu, 14 Jul 2022 11:59:34 +0200 Subject: [PATCH] Fix add-on memory calculation (#3739) Docker versions newer than 19.03 calculate memory usage sligthly different compared to previous versions. It seems the field "total_inactive_file" was not available in 19.03, so it can be used as indicator. See: https://docs.docker.com/engine/reference/commandline/stats/#description --- supervisor/docker/stats.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/supervisor/docker/stats.py b/supervisor/docker/stats.py index b5853f177..49a9e62dd 100644 --- a/supervisor/docker/stats.py +++ b/supervisor/docker/stats.py @@ -14,9 +14,12 @@ class DockerStats: self._blk_write = 0 try: - self._memory_usage = ( - stats["memory_stats"]["usage"] - stats["memory_stats"]["stats"]["cache"] - ) + if "total_inactive_file" in stats["memory_stats"]["stats"]: + cache = stats["memory_stats"]["stats"]["total_inactive_file"] + else: + cache = stats["memory_stats"]["stats"]["cache"] + + self._memory_usage = stats["memory_stats"]["usage"] - cache self._memory_limit = stats["memory_stats"]["limit"] except KeyError: self._memory_usage = 0