Exemplo n.º 1
0
def container_mem_usage(name):
    inst = cgroup(name)

    if inst.cgroup is not None:

        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}}
    else:
        return {}
Exemplo n.º 2
0
def get_virtual_memory():
    cached = active = inactive = None
    f = open('/proc/meminfo', 'r')
    try:
        for line in f:
            if line.startswith('MemTotal:'):
                total = int(line.split()[1])* 1024
            elif line.startswith('MemFree:'):
                free = int (line.split()[1]) * 1024
            elif line.startswith('Buffers:'):
                buffers = int (line.split()[1]) * 1024
            elif line.startswith('Cached:'):
                cached = int(line.split()[1]) * 1024
            elif line.startswith('Active:'):
                active = int(line.split()[1]) * 1024
            elif line.startswith('Inactive:'):
                inactive = int(line.split()[1]) * 1024
            if cached is not None\
               and active is not None\
            and inactive is not None:
                break
        else:
            raise RuntimeError("line(s) not found")
    finally:
        f.close()
    avail = free + buffers + cached
    used = total - free
    percent = usage_percent((total - avail), total, _round=1)
    return nt_virtmem_info(total, avail, percent, used, free, buffers, cached)
Exemplo n.º 3
0
def get_virtual_memory():
    cached = active = inactive = None
    f = open('/proc/meminfo', 'r')
    try:
        for line in f:
            if line.startswith('MemTotal:'):
                total = int(line.split()[1]) * 1024
            elif line.startswith('MemFree:'):
                free = int(line.split()[1]) * 1024
            elif line.startswith('Buffers:'):
                buffers = int(line.split()[1]) * 1024
            elif line.startswith('Cached:'):
                cached = int(line.split()[1]) * 1024
            elif line.startswith('Active:'):
                active = int(line.split()[1]) * 1024
            elif line.startswith('Inactive:'):
                inactive = int(line.split()[1]) * 1024
            if cached is not None\
               and active is not None\
            and inactive is not None:
                break
        else:
            raise RuntimeError("line(s) not found")
    finally:
        f.close()
    avail = free + buffers + cached
    used = total - free
    percent = usage_percent((total - avail), total, _round=1)
    return nt_virtmem_info(total, avail, percent, used, free, buffers, cached)
Exemplo n.º 4
0
def get_disk_usage(path):
    """Return disk usage associated with path."""
    st = os.statvfs(path)
    free = st.f_bavail * st.f_frsize
    total = st.f_blocks * st.f_frsize
    used = (st.f_blocks - st.f_bfree) * st.f_frsize
    percent = usage_percent(used, total,_round=1)
    return nt_diskstatus(total, used, free, percent)
Exemplo n.º 5
0
def container_mem_usage(name):
    inst = 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"))

    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,
        }
    }
Exemplo n.º 6
0
def container_mem_usage(name):
    inst = 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"))

    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
        }
    }