def memory_usage(name): ''' returns memory usage in MB ''' if not exists(name): raise ContainerDoesntExists("The container (%s) does not exist!" % name) if name in stopped(): return 0 cmd = ['lxc-cgroup -n %s memory.usage_in_bytes' % name] try: out = subprocess.check_output(cmd, shell=True).splitlines() except: return 0 return int(out[0])/1024/1024
def max_memory_usage(name): if not exists(name): raise ContainerDoesntExists("The container (%s) does not exist!" % name) if name in stopped(): return 0 cmd = ['lxc-cgroup -n %s memory.limit_in_bytes' % name] try: out = subprocess.check_output(cmd, shell=True).splitlines() except: return 0 host = host_memory_usage() limit = int(out[0])/1024/1024 if limit > host["total"]: limit = host["total"] return limit