Пример #1
0
def collect(conn, fg):
    cur = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
    for dev in NETIFS:
        (ready, rxps, txps) = netifstat(dev)
        if fg > 1:
            print(dev, ready, rxps, txps)
        if ready:
            param = PARAMS['system.net.' + dev + '.rxps']
            lib.update_stat_f(cur, param, rxps)
            param = PARAMS['system.net.' + dev + '.txps']
            lib.update_stat_f(cur, param, txps)
    cur.close()
Пример #2
0
def collect(conn, fg):
    cur = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
    for dev in NETIFS:
        (ready, rxps, txps) = netifstat(dev)
        if fg:
            print(dev, ready, rxps, txps)
        if ready:
            param = PARAMS['system.net.'+dev+'.rxps']
            lib.update_stat_f(cur, param, rxps)
            param = PARAMS['system.net.'+dev+'.txps']
            lib.update_stat_f(cur, param, txps)
    cur.close()
Пример #3
0
def collect(conn, fg):
    cur = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
    try:
        stat = open('/proc/meminfo')
    except IOError:
        return 0
    # read all memory info into buffer
    data = stat.read()
    stat.close()
    for line in data.splitlines():
        try:
            name, value, units = line.split()
            name = name.rstrip(':')
            value = int(value)
            if name not in KEY_MAPPING:
                continue
        except ValueError:
            continue
        if 'kB' == units:
            value *= 1024
        elif 'MB' == units:
            value *= 1049586
        elif 'GB' == units:
            value *= 1024 * 1048576
        if fg:
            print (name, value)
        param = PARAMS[name]
        lib.update_stat_n(cur, param, value)
        if name in ('MemTotal', 'MemFree'):
            SYNTH[name] = value
    if SYNTH.get('MemTotal', 0):
        used = SYNTH['MemTotal'] - SYNTH['MemFree']
        util = used * 100.0 / SYNTH['MemTotal']
        if fg:
            print (used, util)
        param = PARAMS['_Memory_Used']
        lib.update_stat_n(cur, param, used)
        param = PARAMS['_Memory_Util']
        lib.update_stat_f(cur, param, util)
    cur.close()
Пример #4
0
def collect(conn, fg):
    cur = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
    for dev in DISKS:
        (ready, iops, readps, writeps) = diskstat(dev, fg)
        if fg:
            print(ready, iops, readps, writeps)
        if ready:
            param = PARAMS['system.disk.'+NAMES[dev]+'.iops']
            lib.update_stat_f(cur, param, iops)
            param = PARAMS['system.disk.'+NAMES[dev]+'.readps']
            lib.update_stat_f(cur, param, readps)
            param = PARAMS['system.disk.'+NAMES[dev]+'.writeps']
            lib.update_stat_f(cur, param, writeps)
    cur.close()
Пример #5
0
def collect(conn, fg):
    cur = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
    for dev in DISKS:
        (ready, iops, readps, writeps) = diskstat(dev, fg)
        if fg:
            print(ready, iops, readps, writeps)
        if ready:
            param = PARAMS['system.disk.' + NAMES[dev] + '.iops']
            lib.update_stat_f(cur, param, iops)
            param = PARAMS['system.disk.' + NAMES[dev] + '.readps']
            lib.update_stat_f(cur, param, readps)
            param = PARAMS['system.disk.' + NAMES[dev] + '.writeps']
            lib.update_stat_f(cur, param, writeps)
    cur.close()
Пример #6
0
def collect(conn, fg):
    cur = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
    (ready, util, user, system, iowait) = cpustat()
    if fg:
        print(ready, util, user, system, iowait)
    if ready:
        param = PARAMS['system.cpu.util']
        lib.update_stat_f(cur, param, util)
        param = PARAMS['system.cpu.util.user']
        lib.update_stat_f(cur, param, user)
        param = PARAMS['system.cpu.util.system']
        lib.update_stat_f(cur, param, system)
        param = PARAMS['system.cpu.util.iowait']
        lib.update_stat_f(cur, param, iowait)

    (ready, l1, l5, l15) = loadavgstat()
    if fg:
        print(ready, l1, l5, l15)
    if ready:
        param = PARAMS['system.cpu.loadavg.1m']
        lib.update_stat_f(cur, param, l1)
        param = PARAMS['system.cpu.loadavg.5m']
        lib.update_stat_f(cur, param, l5)
        param = PARAMS['system.cpu.loadavg.15m']
        lib.update_stat_f(cur, param, l15)

    cur.close()
Пример #7
0
def collect(conn, fg):
    cur = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
    (ready, util, user, system, iowait) = cpustat()
    if fg:
        print(ready, util, user, system, iowait)
    if ready:
        param = PARAMS['system.cpu.util']
        lib.update_stat_f(cur, param, util)
        param = PARAMS['system.cpu.util.user']
        lib.update_stat_f(cur, param, user)
        param = PARAMS['system.cpu.util.system']
        lib.update_stat_f(cur, param, system)
        param = PARAMS['system.cpu.util.iowait']
        lib.update_stat_f(cur, param, iowait)

    (ready, l1, l5, l15) = loadavgstat()
    if fg:
        print(ready, l1, l5, l15)
    if ready:
        param = PARAMS['system.cpu.loadavg.1m']
        lib.update_stat_f(cur, param, l1)
        param = PARAMS['system.cpu.loadavg.5m']
        lib.update_stat_f(cur, param, l5)
        param = PARAMS['system.cpu.loadavg.15m']
        lib.update_stat_f(cur, param, l15)

    cur.close()