예제 #1
0
def get_device_info(path):
    try:
        info = psutil.disk_usage(os.path.realpath(path))
        return {
            "total": humanize_bytes(info.total),
            "used": humanize_bytes(info.used),
            "free": humanize_bytes(info.free)
        }
    except OSError as e:
        return {"ERROR": str(e)}
예제 #2
0
def get_host(**kwargs):
    mem = psutil.virtual_memory()
    host = OrderedDict()
    host["hostname"] = socket.gethostname()
    host["fqdn"] = socket.getfqdn()
    host["cpus"] = psutil.cpu_count()
    host["network"] = get_network()

    host["memory"] = {
        "total": humanize_bytes(mem.total),
        "available": humanize_bytes(mem.available),
        "percent": humanize_bytes(mem.percent),
        "used": humanize_bytes(mem.used),
        "free": humanize_bytes(mem.free)
    }
    return host
예제 #3
0
def get_queues(**kwargs):
    redis = get_redis_connection()
    res = OrderedDict()
    queue_names = [
        'router', 'postman', 'smtp', 'incheck', 'maillist', 'forward', 'dkim',
        'review'
    ]
    for n in queue_names:
        lock_key = 'task_lock:' + n
        wait_key = 'task_queue:' + n
        file_path = os.path.join('/usr/local/u-mail/app/data/',
                                 'cache_{}'.format(n))
        res[n] = {
            'wait': redis.llen(wait_key),
            'lock': redis.scard(lock_key),
            'size': humanize_bytes(getFileSize(file_path))
        }
    return res
예제 #4
0
def get_host(**kwargs):
    host = {}
    try:
        mem = psutil.virtual_memory()
        swap = psutil.swap_memory()
        disk_partitions = psutil.disk_partitions()
        host = OrderedDict()
        host["hostname"] = socket.gethostname()
        host["fqdn"] = socket.getfqdn()

        host["memory"] = {
            "total": humanize_bytes(mem.total),
            "available": humanize_bytes(mem.available),
            "percent": mem.percent,
            "used": humanize_bytes(mem.used),
            "free": humanize_bytes(mem.free),
            "buffers": humanize_bytes(mem.buffers),
            "cached": humanize_bytes(mem.cached),
        }

        host["swap"] = {
            "total": humanize_bytes(swap.total),
            "percent": swap.percent,
            "used": humanize_bytes(swap.used),
            "free": humanize_bytes(swap.free)
        }
        disks = []

        for a in disk_partitions:
            disk = a.__dict__
            d = psutil.disk_usage(a.mountpoint)
            disk['total'] = humanize_bytes(d.total)
            disk['used'] = humanize_bytes(d.used)
            disk['free'] = humanize_bytes(d.free)
            disk['percent'] = d.percent
            disks.append(disk)
        host["disk"] = disks
    except Exception, err:
        print err