diff --git a/check_docker/check_docker.py b/check_docker/check_docker.py index 1a9d754..37bdd5d 100755 --- a/check_docker/check_docker.py +++ b/check_docker/check_docker.py @@ -520,7 +520,14 @@ def check_memory(container, thresholds): inspection = get_stats(container) # Subtracting cache to match what `docker stats` does. - adjusted_usage = inspection['memory_stats']['usage'] - inspection['memory_stats']['stats']['total_cache'] + adjusted_usage = inspection['memory_stats']['usage'] + if 'total_cache' in inspection['memory_stats']['stats']: + # CGroups v1 - https://www.kernel.org/doc/Documentation/cgroup-v1/memory.txt + adjusted_usage -= inspection['memory_stats']['stats']['total_cache'] + elif 'inactive_file' in inspection['memory_stats']['stats']: + # CGroups v2 - https://www.kernel.org/doc/Documentation/cgroup-v2.txt + adjusted_usage -= inspection['memory_stats']['stats']['inactive_file'] + if thresholds.units == '%': max = 100 usage = int(100 * adjusted_usage / inspection['memory_stats']['limit'])