Catch cgroup errors, return no stats
This commit is contained in:
parent
d6f19e05f9
commit
0a8793e44b
|
@ -150,18 +150,30 @@ def run_module():
|
||||||
|
|
||||||
res_stat = {}
|
res_stat = {}
|
||||||
if ct.running:
|
if ct.running:
|
||||||
res_stat['mem'] = {
|
res_stat['mem'] = {}
|
||||||
'usage': int(ct.get_cgroup_item("memory.usage_in_bytes")),
|
for (k, v) in [ ('usage', 'memory.usage_in_bytes'), ('max_usage', 'memory.max_usage_in_bytes') ]:
|
||||||
'max_usage': int(ct.get_cgroup_item("memory.max_usage_in_bytes")),
|
try:
|
||||||
'usage_mb': int(ct.get_cgroup_item("memory.usage_in_bytes")) // 1048576,
|
res_stat['mem'][k] = int(ct.get_cgroup_item(v))
|
||||||
'max_usage_mb': int(ct.get_cgroup_item("memory.max_usage_in_bytes")) // 1048576,
|
except KeyError:
|
||||||
}
|
pass
|
||||||
res_stat['kmem'] = {
|
for (k, v) in [ ('usage_mb', 'memory.usage_in_bytes'), ('max_usage_mb', 'memory.max_usage_in_bytes') ]:
|
||||||
'usage': int(ct.get_cgroup_item("memory.kmem.usage_in_bytes")),
|
try:
|
||||||
'max_usage': int(ct.get_cgroup_item("memory.kmem.max_usage_in_bytes")),
|
res_stat['mem'][k] = int(ct.get_cgroup_item(v)) // 1048576
|
||||||
'usage_mb': int(ct.get_cgroup_item("memory.kmem.usage_in_bytes")) // 1048576,
|
except KeyError:
|
||||||
'max_usage_mb': int(ct.get_cgroup_item("memory.kmem.max_usage_in_bytes")) // 1048576,
|
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
|
res_ct['stats'] = res_stat
|
||||||
|
|
||||||
result['containers'][ctname] = res_ct
|
result['containers'][ctname] = res_ct
|
||||||
|
|
Loading…
Reference in a new issue