From 24bbe7c31fba6f17649b0867ec22e2ba6f3a3912 Mon Sep 17 00:00:00 2001 From: xinwen Date: Tue, 30 Nov 2021 15:21:07 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=AE=A1=E7=AE=97docker=20limit=20?= =?UTF-8?q?=E5=86=85=E5=AD=98=E4=BD=BF=E7=94=A8=E7=8E=87=E6=97=B6=E5=8C=BA?= =?UTF-8?q?=E5=88=86=20cgroup=20v1=20v2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/common/utils/common.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/apps/common/utils/common.py b/apps/common/utils/common.py index 3bdcfa622..e61db38ed 100644 --- a/apps/common/utils/common.py +++ b/apps/common/utils/common.py @@ -264,11 +264,18 @@ def get_docker_mem_usage_if_limit(): usage_in_bytes = int(f.readline()) with open('/sys/fs/cgroup/memory/memory.stat') as f: - lines = f.readlines() - name, value = lines[33].split() - total_inactive_file = int(value) + inactive_file = 0 + for line in f: + if line.startswith('total_inactive_file'): + name, inactive_file = line.split() + break - return ((usage_in_bytes - total_inactive_file) / limit_in_bytes) * 100 + if line.startswith('inactive_file'): + name, inactive_file = line.split() + continue + + inactive_file = int(inactive_file) + return ((usage_in_bytes - inactive_file) / limit_in_bytes) * 100 except Exception as e: logger.error(f'Get memory usage by docker limit: {e}')