Catch cgroup errors, return no stats

This commit is contained in:
Sven Velt 2024-11-20 16:22:55 +01:00
parent d6f19e05f9
commit 0a8793e44b

View file

@ -150,18 +150,30 @@ def run_module():
res_stat = {}
if ct.running:
res_stat['mem'] = {
'usage': int(ct.get_cgroup_item("memory.usage_in_bytes")),
'max_usage': int(ct.get_cgroup_item("memory.max_usage_in_bytes")),
'usage_mb': int(ct.get_cgroup_item("memory.usage_in_bytes")) // 1048576,
'max_usage_mb': int(ct.get_cgroup_item("memory.max_usage_in_bytes")) // 1048576,
}
res_stat['kmem'] = {
'usage': int(ct.get_cgroup_item("memory.kmem.usage_in_bytes")),
'max_usage': int(ct.get_cgroup_item("memory.kmem.max_usage_in_bytes")),
'usage_mb': int(ct.get_cgroup_item("memory.kmem.usage_in_bytes")) // 1048576,
'max_usage_mb': int(ct.get_cgroup_item("memory.kmem.max_usage_in_bytes")) // 1048576,
}
res_stat['mem'] = {}
for (k, v) in [ ('usage', 'memory.usage_in_bytes'), ('max_usage', 'memory.max_usage_in_bytes') ]:
try:
res_stat['mem'][k] = int(ct.get_cgroup_item(v))
except KeyError:
pass
for (k, v) in [ ('usage_mb', 'memory.usage_in_bytes'), ('max_usage_mb', 'memory.max_usage_in_bytes') ]:
try:
res_stat['mem'][k] = int(ct.get_cgroup_item(v)) // 1048576
except KeyError:
pass
res_stat['kmem'] = {}
for (k, v) in [ ('usage', 'memory.kmem.usage_in_bytes'), ('max_usage', 'memory.kmem.max_usage_in_bytes') ]:
try:
res_stat['kmem'][k] = int(ct.get_cgroup_item(v))
except KeyError:
pass
for (k, v) in [ ('usage_mb', 'memory.kmem.usage_in_bytes'), ('max_usage_mb', 'memory.kmem.max_usage_in_bytes') ]:
try:
res_stat['kmem'][k] = int(ct.get_cgroup_item(v)) // 1048576
except KeyError:
pass
res_ct['stats'] = res_stat
result['containers'][ctname] = res_ct