コード例 #1
0
def distr_get():  # noqa: E501
    key = util.key()
    if key == 401:
        return 'Invalid key', 401
    dist = platform.linux_distribution()
    distinfo = {'distname': dist[0], 'version': dist[1], 'id': dist[2]}
    return distinfo    
コード例 #2
0
def ports_get():
    data = []
    key = util.key()
    if key == 401:
        return 'Invalid key', 401
    for c in psutil.net_connections(kind='inet'):
        laddr = "%s %s" % (c.laddr)
        data.append(laddr.split()[1])
    return list(set(data))
コード例 #3
0
def mem_detail_get(detail):  # noqa: E501
    key = util.key()
    if key == 401:
        return 'Invalid key', 401

    if detail == 'virtual':
        result = psutil.virtual_memory()
    elif detail == 'swap':
        result = psutil.swap_memory()
    return result
コード例 #4
0
def disk_detail_get(detail):  # noqa: E501
    key = util.key()
    if key == 401:
        return 'Invalid key', 401
    if detail == 'partitions':
        result = disk_detail()
    elif detail == 'disk_io_counters':
        result = psutil.disk_io_counters(perdisk=True)
    elif detail == 'disk_rw':
        result = disk_rw()
    return result
コード例 #5
0
def net_detail_get(detail):  # noqa: E501
    key = util.key()
    if key == 401:
        return 'Invalid key', 401

    if detail == 'addr':
        result = address_info()

    if detail == 'counters':
        result = net_counters()

    return result
コード例 #6
0
def service_service_get(service):  # noqa: E501
    key = util.key()
    if key == 401:
        return 'Invalid key', 401

    service = service.encode()
    output = subprocess.check_output(['ps', '-A'])
    if service in output:
        result = 1
    else:
        result = 0

    return result
コード例 #7
0
def cpu_detail_get(detail):  # noqa: E501
    key = util.key()
    if key == 401:
        return 'Invalid key', 401

    if detail == 'info':
        result = cpuinfo()
    elif detail == 'cpu_times':
        result = psutil.cpu_times()
    elif detail == 'cpu_percent':
        result = psutil.cpu_percent(interval=1, percpu=True)
    elif detail == 'cpu_percent_total':
        result = psutil.cpu_percent(interval=1)
    elif detail == 'cpu_stats':
        result = psutil.cpu_stats()
    elif detail == 'cpu_freq':
        result = psutil.cpu_freq(percpu=True)

    return result
コード例 #8
0
def boot_time_get():  # noqa: E501
    key = util.key()
    if key == 401:
        return 'Invalid key', 401
    boot_time = (datetime.datetime.fromtimestamp(psutil.boot_time()).strftime("%Y-%m-%d %H:%M:%S"))
    return boot_time
コード例 #9
0
def top5mem_get():  # noqa: E501
    key = util.key()
    if key == 401:
        return 'Invalid key', 401
    top_mem = ([(p.pid, p.info) for p in sorted(psutil.process_iter(attrs=['name', 'memory_percent']), key=lambda p: p.info['memory_percent'])][-5:])
    return top_mem
コード例 #10
0
def top5cpu_get():  # noqa: E501
    key = util.key()
    if key == 401:
        return 'Invalid key', 401
    top_cpu = ([(p.pid, p.info['name'], sum(p.info['cpu_times'])) for p in sorted(psutil.process_iter(attrs=['name', 'cpu_times']), key=lambda p: sum(p.info['cpu_times'][:2]))][-5:])
    return top_cpu
コード例 #11
0
def python_get():  # noqa: E501
    key = util.key()
    if key == 401:
        return 'Invalid key', 401
    return platform.python_version()
コード例 #12
0
def la_get():  # noqa: E501
    key = util.key()
    if key == 401:
        return 'Invalid key', 401
    load = json.dumps(os.getloadavg())
    return load
コード例 #13
0
def hostname_get():  # noqa: E501
    key = util.key()
    if key == 401:
        return 'Invalid key', 401
    fqdn = socket.getfqdn()
    return fqdn
コード例 #14
0
def agent_get():  # noqa: E501
    key = util.key()
    if key == 401:
        return 'Invalid key', 401
    return config.ver
コード例 #15
0
def key_get():  # noqa: E501
    key = util.key()
    if key == 401:
        return 'Invalid key', 401
    return 'Authorized', 200