Exemplo n.º 1
0
def report_sum(name, start=None, end=None):

    # fetch data from our RRD's

    rrdargs = [
        os.path.join(cfg.VAR_DB_OPENVPS, 'vsmon', name + '.rrd'), 'AVERAGE'
    ]

    if start:
        rrdargs.append('--start')
        rrdargs.append(start)
    if end:
        rrdargs.append('--end')
        rrdargs.append(end)

    header, rows = RRD.fetch(*rrdargs)

    step = int(rows[1][0] - rows[0][0])

    result = {
        'start': rows[0][0],
        'end': rows[-1][0],
        'step': step,
        'steps': len(rows),
        'ticks': 0,
        'vm': 0,
        'rss': 0,
        'in': 0,
        'out': 0,
        'disk': 0,
    }

    for row in rows:

        ticks = _sum_none(header, row, ['vs_uticks', 'vs_sticks'])
        result['ticks'] += ticks
        result['vm'] += _sum_none(header, row, ['vs_vm'])
        result['rss'] += _sum_none(header, row, ['vs_rss'])
        result['in'] += _sum_none(header, row, ['vs_in'])
        result['out'] += _sum_none(header, row, ['vs_out'])
        result['disk'] += _sum_none(header, row, ['vs_disk_b_used'])

    # a COUNTER is always per-second. To get the actual number, it
    # is AVG * STEP (where step is in seconds)

    # a GAUGE is an average (i.e. not per-second). If our tokens are
    # based on a per-minute interval, then the total tokens would be
    # sum(averages) * (STEP/60)

    result['ticks'] = result['ticks'] * step  # counter
    result['vm'] = result['vm'] * (step / 60)  # gauge
    result['rss'] = result['rss'] * (step / 60)  # gauge
    result['in'] = result['in'] * step  # counter
    result['out'] = result['out'] * step  # counter
    result['disk'] = result['disk'] * (step / 60)  # gauge

    return result
Exemplo n.º 2
0
def report_sum(name, start=None, end=None):

    # fetch data from our RRD's

    rrdargs = [os.path.join(cfg.VAR_DB_OPENVPS, "vsmon", name + ".rrd"), "AVERAGE"]

    if start:
        rrdargs.append("--start")
        rrdargs.append(start)
    if end:
        rrdargs.append("--end")
        rrdargs.append(end)

    header, rows = RRD.fetch(*rrdargs)

    step = int(rows[1][0] - rows[0][0])

    result = {
        "start": rows[0][0],
        "end": rows[-1][0],
        "step": step,
        "steps": len(rows),
        "ticks": 0,
        "vm": 0,
        "rss": 0,
        "in": 0,
        "out": 0,
        "disk": 0,
    }

    for row in rows:

        ticks = _sum_none(header, row, ["vs_uticks", "vs_sticks"])
        result["ticks"] += ticks
        result["vm"] += _sum_none(header, row, ["vs_vm"])
        result["rss"] += _sum_none(header, row, ["vs_rss"])
        result["in"] += _sum_none(header, row, ["vs_in"])
        result["out"] += _sum_none(header, row, ["vs_out"])
        result["disk"] += _sum_none(header, row, ["vs_disk_b_used"])

    # a COUNTER is always per-second. To get the actual number, it
    # is AVG * STEP (where step is in seconds)

    # a GAUGE is an average (i.e. not per-second). If our tokens are
    # based on a per-minute interval, then the total tokens would be
    # sum(averages) * (STEP/60)

    result["ticks"] = result["ticks"] * step  # counter
    result["vm"] = result["vm"] * (step / 60)  # gauge
    result["rss"] = result["rss"] * (step / 60)  # gauge
    result["in"] = result["in"] * step  # counter
    result["out"] = result["out"] * step  # counter
    result["disk"] = result["disk"] * (step / 60)  # gauge

    return result
Exemplo n.º 3
0
def period_total(rrd, start, end, dslist=['in', 'out']):

    start, end = int(float(start)), int(float(end))

    header, rows = RRD.fetch(rrd, 'AVERAGE', '-s', str(start), '-e', str(end))

    step = rows[1][0] - rows[0][0]

    # convert DS names to numeric indecies
    dslist = [list(header).index(x) for x in dslist]

    totals = [0] * len(dslist)

    for row in rows:
        n = 0
        for ds_idx in dslist:
            if row[ds_idx]:
                totals[n] += row[ds_idx]
            n += 1

    return step, totals
Exemplo n.º 4
0
def period_total(rrd, start, end, dslist=["in", "out"]):

    start, end = int(float(start)), int(float(end))

    header, rows = RRD.fetch(rrd, "AVERAGE", "-s", str(start), "-e", str(end))

    step = rows[1][0] - rows[0][0]

    # convert DS names to numeric indecies
    dslist = [list(header).index(x) for x in dslist]

    totals = [0] * len(dslist)

    for row in rows:
        n = 0
        for ds_idx in dslist:
            if row[ds_idx]:
                totals[n] += row[ds_idx]
            n += 1

    return step, totals