Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions custom_components/monitor_docker/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -874,10 +874,12 @@ async def _run_container_stats(self):
# Compatibility wih older Docker API
if "online_cpus" in raw["cpu_stats"]:
cpu_stats["online_cpus"] = raw["cpu_stats"]["online_cpus"]
else:
elif "percpu_usage" in raw["cpu_stats"]["cpu_usage"]:
cpu_stats["online_cpus"] = len(
raw["cpu_stats"]["cpu_usage"]["percpu_usage"] or []
)
else:
cpu_stats["online_cpus"] = 1

# Calculate cpu usage, but first iteration we don't know it
if self._cpu_old:
Expand Down Expand Up @@ -936,20 +938,21 @@ async def _run_container_stats(self):

cache = 0
# https://docs.docker.com/engine/reference/commandline/stats/
if self._version1904:
# 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"]
else:
# Version is 19.03 and lower, use "cache"
if "cache" in raw["memory_stats"]["stats"]:
cache = raw["memory_stats"]["stats"]["cache"]
elif "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 self._version1904:
# 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"]
else:
# Version is 19.03 and lower, use "cache"
if "cache" in raw["memory_stats"]["stats"]:
cache = raw["memory_stats"]["stats"]["cache"]
elif "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,
Expand Down