def container_mem_usage(name): inst = cgroup('memory', name) memlimit = int(inst.getValue("memory.limit_in_bytes")) memswlimit = int(inst.getValue("memory.memsw.limit_in_bytes")) memused = int(inst.getValue("memory.usage_in_bytes")) memswused = int(inst.getValue("memory.memsw.usage_in_bytes")) mem_total = memlimit mem_used = memused mem_free = memlimit-memused mem_percent_used = usage_percent(mem_used, mem_total, _round=1) swap_total = memswlimit-memlimit swap_used = memswused-memused swap_free = swap_total -swap_used swap_percent_used = usage_percent(swap_used, swap_total, _round=1) total = memswlimit total_used = memswused total_free = memswlimit-memswused total_percent_used = usage_percent(total_used, total, _round=1) return {'memory':{'mem_total': mem_total, 'mem_used': mem_used, 'mem_free': mem_free, 'mem_percent_used': mem_percent_used, 'swap_total':swap_total, 'swap_used': swap_used, 'swap_free': swap_free, 'swap_percent_used': swap_percent_used, 'total': total, 'total_used': total_used, 'total_free': total_free, 'total_percent_used': total_percent_used}}
def container_cpu_usage( name): inst = cgroup('cpuacct', name) previous_cpu_usage = inst.getValue("cpuacct.usage") time.sleep(interval) current_cpu_usage = inst.getValue("cpuacct.usage") diff_cpu_usage = int(current_cpu_usage) - int(previous_cpu_usage) cpu_usage = float(diff_cpu_usage/(interval*1000000000))*100 return {'cpu':{'cpu_usage': cpu_usage}}