Exemplo n.º 1
0
def ContainerMemUsage(name):
	inst = lxc.cgroup(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"))

	print "         %12s	%12s	%12s	%12s" % ("total","used","free", "percent used")
	print "Mem  :	%12i	%12i	%12i	%12i" % (byte2MiByte(memlimit),byte2MiByte(memused),byte2MiByte(memlimit-memused), memused/float(memlimit)*100)
	print "Swap :	%12i	%12i	%12i	%12i" % (byte2MiByte(memswlimit-memlimit),byte2MiByte(memswused-memused),byte2MiByte(memswlimit-memlimit-(memswused-memused)), (memswused-memused)/float(memswlimit-memlimit)*100)
	print "Total:	%12i	%12i	%12i	%12i" % (byte2MiByte(memswlimit),byte2MiByte(memswused),byte2MiByte(memswlimit-memswused), memswused/float(memswlimit)*100)
hosts = []
if args.all:
    hosts = lxc.getRunningContainers()
else:
    hosts.append(args.container)

state = {}
state["critical"] = []
state["warn"] = []
state["ok"] = []
state["notrunning"] = []

for host in hosts:
    inst = None
    try:
        inst = lxc.cgroup(host)
    except lxc.CGroupNotFound:
        addState(host, "notrunning", state)
        continue

    if not args.disable_mem:
        memused = int(inst.getValue("memory.usage_in_bytes"))
        memlimit = int(inst.getValue("memory.limit_in_bytes"))
        checkValues(host, percent(memused, memlimit), args.warn, args.critical, state)
    if not args.disable_memsw:
        memswused = int(inst.getValue("memory.memsw.usage_in_bytes"))
        memswlimit = int(inst.getValue("memory.memsw.limit_in_bytes"))
        checkValues(host, percent(memswused, memswlimit), args.warn, args.critical, state)
    if args.failcount:
        memfailcnt = int(inst.getValue("memory.failcnt"))
        if memfailcnt > 0: