fix: 计算docker limit 内存使用率时区分 cgroup v1 v2

pull/7331/head
xinwen 3 years ago committed by 老广
parent 77f2bd9262
commit 24bbe7c31f

@ -264,11 +264,18 @@ def get_docker_mem_usage_if_limit():
usage_in_bytes = int(f.readline()) usage_in_bytes = int(f.readline())
with open('/sys/fs/cgroup/memory/memory.stat') as f: with open('/sys/fs/cgroup/memory/memory.stat') as f:
lines = f.readlines() inactive_file = 0
name, value = lines[33].split() for line in f:
total_inactive_file = int(value) if line.startswith('total_inactive_file'):
name, inactive_file = line.split()
return ((usage_in_bytes - total_inactive_file) / limit_in_bytes) * 100 break
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: except Exception as e:
logger.error(f'Get memory usage by docker limit: {e}') logger.error(f'Get memory usage by docker limit: {e}')

Loading…
Cancel
Save