Exemple #1
0
def send_summary_graph(start, end):
    """Sends summary graph."""
    probes = flask.request.args.get('probes')
    if probes:
        probes = probes.split(',')
        probes = [probe.encode('utf-8') for probe in probes]
        for probe in probes:
            if probe not in flask.request.probes:
                flask.abort(404)
    else:
        probes = list(flask.request.probes)
    start = start.encode('utf-8')
    end = end.encode('utf-8')
    png_file = rrd.build_graph(int(start), int(end), probes, True)
    tmp_file = tempfile.NamedTemporaryFile()
    shutil.copy2(png_file, tmp_file.name)
    if not png_file.endswith('summary.png'):
        os.unlink(png_file)
    try:
        return flask.send_file(tmp_file,
                               mimetype='image/png',
                               cache_timeout=0,
                               conditional=True)
    except:
        flask.abort(404)
Exemple #2
0
def send_summary_graph(scale):
    """Sends summary graph."""
    scale = scale.encode('utf-8')
    png_file = rrd.build_graph(scale)
    try:
        return flask.send_file(png_file, cache_timeout=0, conditional=True)
    except:
        flask.abort(404)
Exemple #3
0
def send_summary_graph(scale):
    """Sends summary graph."""
    scale = scale.encode('utf-8')
    png_file = rrd.build_graph(scale)
    try:
        return flask.send_file(png_file, cache_timeout=0, conditional=True)
    except:
        flask.abort(404)
Exemple #4
0
def send_probe_graph(scale, probe):
    """Sends graph."""
    probe = probe.encode('utf-8')
    scale = scale.encode('utf-8')
    png_file = rrd.build_graph(scale, probe)
    try:
        return flask.send_file(png_file, cache_timeout=0, conditional=True)
    except:
        flask.abort(404)
Exemple #5
0
def send_probe_graph(scale, probe):
    """Sends graph."""
    probe = probe.encode('utf-8')
    scale = scale.encode('utf-8')
    png_file = rrd.build_graph(scale, probe)
    try:
        return flask.send_file(png_file, cache_timeout=0, conditional=True)
    except:
        flask.abort(404)
Exemple #6
0
def send_probe_graph(probe, start, end):
    """Sends graph."""
    probe = probe.encode('utf-8')
    start = start.encode('utf-8')
    end = end.encode('utf-8')
    png_file = rrd.build_graph(int(start), int(end), probe, False)
    try:
        return flask.send_file(png_file, cache_timeout=0, conditional=True)
    except:
        flask.abort(404)
Exemple #7
0
def send_zip():
    """Sends zip file."""
    probes = flask.request.args.get('probes')
    if probes:
        probes = probes.split(',')
    else:
        probes = flask.request.probes
    tmp_file = tempfile.NamedTemporaryFile()
    zip_file = zipfile.ZipFile(tmp_file.name, 'w')
    probes_selected = []
    for metric in ['power', 'network_in', 'network_out']:
        for probe in probes:
            if os.path.exists(rrd.get_rrd_filename(probe, metric)):
                probes_selected.append(probe.encode('utf8'))
    probes = probes_selected
    for metric in ['power', 'network_in', 'network_out']:
        if len(probes) == 1:
            probe = probes[0]
            rrd_file = rrd.get_rrd_filename(probe,metric)
            zip_file.write(rrd_file, '/rrd/' + probe + '.rrd')
            for scale in ['minute', 'hour', 'day', 'week', 'month', 'year']:
                png_file = rrd.build_graph(int(time.time()) - flask.request.scales[scale][0]['interval'], int(time.time()), probe, False)
                zip_file.write(png_file, '/png/' + probe + '-' + scale + '.png')
        elif len(probes) > 1:
            for probe in probes:
                rrd_file = rrd.get_rrd_filename(probe, metric)
                zip_file.write(rrd_file, '/rrd/' + probe + '.rrd')
                for scale in ['minute', 'hour', 'day', 'week', 'month', 'year']:
                    png_file = rrd.build_graph(int(time.time()) - flask.request.scales[scale][0]['interval'], int(time.time()), probe, False)
                    zip_file.write(png_file, '/png/' + probe + '/' + scale + '.png')
            for scale in ['minute', 'hour', 'day', 'week', 'month', 'year']:
                png_file = rrd.build_graph(int(time.time()) - flask.request.scales[scale][0]['interval'], int(time.time()), probes, True)
                zip_file.write(png_file, '/png/summary-' + scale + '.png')
    else:
        flask.abort(404)
    return flask.send_file(tmp_file,
                           as_attachment=True,
                           attachment_filename='rrd.zip',
                           cache_timeout=0,
                           conditional=True)