Commit 869d48f4 by Stéphane Graber

lxc-ls: Fix memory reporting

This resolves the memory math when memsw is enabled and fixes reporting of nested containers memory when using cgmanager. Signed-off-by: 's avatarStéphane Graber <stgraber@ubuntu.com> Acked-by: 's avatarSerge E. Hallyn <serge.hallyn@ubuntu.com>
parent 04612e33
...@@ -272,20 +272,22 @@ def get_containers(fd=None, base="/", root=False): ...@@ -272,20 +272,22 @@ def get_containers(fd=None, base="/", root=False):
if container.running: if container.running:
try: try:
memory_total = int(container.get_cgroup_item( memory_ram = int(container.get_cgroup_item(
"memory.usage_in_bytes")) "memory.usage_in_bytes"))
except: except:
memory_total = 0 memory_ram = 0
try: try:
memory_swap = int(container.get_cgroup_item( memory_swap = int(container.get_cgroup_item(
"memory.memsw.usage_in_bytes")) "memory.memsw.usage_in_bytes")) - memory_ram
except: except:
memory_swap = 0 memory_swap = 0
else: else:
memory_total = 0 memory_ram = 0
memory_swap = 0 memory_swap = 0
memory_total = memory_ram + memory_swap
if 'memory' in args.fancy_format: if 'memory' in args.fancy_format:
if container.running: if container.running:
entry['memory'] = "%sMB" % round(memory_total / 1048576, 2) entry['memory'] = "%sMB" % round(memory_total / 1048576, 2)
...@@ -294,8 +296,7 @@ def get_containers(fd=None, base="/", root=False): ...@@ -294,8 +296,7 @@ def get_containers(fd=None, base="/", root=False):
if 'ram' in args.fancy_format: if 'ram' in args.fancy_format:
if container.running: if container.running:
entry['ram'] = "%sMB" % round( entry['ram'] = "%sMB" % round(memory_ram / 1048576, 2)
(memory_total - memory_swap) / 1048576, 2)
else: else:
entry['ram'] = "-" entry['ram'] = "-"
...@@ -330,8 +331,7 @@ def get_containers(fd=None, base="/", root=False): ...@@ -330,8 +331,7 @@ def get_containers(fd=None, base="/", root=False):
temp_fd, temp_file = tempfile.mkstemp() temp_fd, temp_file = tempfile.mkstemp()
os.remove(temp_file) os.remove(temp_file)
container.attach_wait(get_containers, temp_fd, container.attach_wait(get_containers, temp_fd)
attach_flags=0)
json_file = os.fdopen(temp_fd, "r") json_file = os.fdopen(temp_fd, "r")
json_file.seek(0) json_file.seek(0)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment