def build_graph_network_init(start, end, probes, summary, zip_file=False): """Builds the graph for the probes, or a summary graph.""" # Graph is cachable ? cachable = False intervals = {} for scale in scales: intervals[scales[scale][0]['interval']] = { 'resolution': scales[scale][0]['resolution'], 'name': scale } scale = None if end - start in intervals: scale = intervals[end - start]['name'] if end >= int(time.time()) - scales[scale][0]['resolution']: cachable = True # Retrieve probes (and multi-probes) if not isinstance(probes, list): probes = [probes] if len(probes) == 0: probes = list(probes_set_network) if not isinstance(probes, list): probes = [probes] probes = filter(lambda p: p in probes_set_network, probes) probes_in = set() probes_out = set() for probe in probes: for probe in find_probe_uid('network', probe): if get_rrd_filename(probe, "network_in") and get_rrd_filename(probe, "network_out"): probes_in.add(probe) probes_out.add(probe) probes_in = list(probes_in) probes_out = list(probes_out) # Single probe and no summary if len(probes) == 1 and not summary and scale: png_file = get_png_filename(probes[0], "network_in", scale) # All probes summary elif len(probes) == len(probes_set_network) and summary: png_file = cfg.CONF.png_dir + '/' + scale + '/summary-network.png' # Other combinaison else: png_file = NamedTemporaryFile(prefix="kwapi", suffix=".png").name if zip_file: #Force temporary name png_file = NamedTemporaryFile(prefix="kwapi", suffix=".png").name # Get the file from cache if cachable and os.path.exists(png_file) and os.path.getmtime(png_file) > \ time.time() - scales[scale][0]['resolution']: return png_file else: return build_graph_network(start, end, probes, probes_in, probes_out, summary, cachable, png_file, scale)
def build_graph_energy_init(start, end, probes, summary, zip_file=False): """Builds the graph for the probes, or a summary graph.""" # Graph is cachable ? cachable = False intervals = {} for scale in scales: intervals[scales[scale][0]['interval']] = { 'resolution': scales[scale][0]['resolution'], 'name': scale } scale = None if end - start in intervals: scale = intervals[end - start]['name'] if end >= int(time.time()) - scales[scale][0]['resolution']: cachable = True if not isinstance(probes, list): probes = [probes] # Retrieve probes (and multi-probes) if len(probes) == 0: probes = list(probes_set_power) if not isinstance(probes, list): probes = [probes] probes = filter(lambda p: p in probes_set_power, probes) multi_probes_selected = set() for probe in probes: multi_probes_selected = multi_probes_selected.union(find_multi_probe(probe, 'power')) probes_uid = list(multi_probes_selected) # Single probe and no summary if len(probes) == 1 and not summary and scale: png_file = get_png_filename(probes[0], "power", scale) # All probes summary elif len(probes) == len(probes_set_power) and summary: png_file = cfg.CONF.png_dir + '/' + scale + '/summary-energy.png' # Other combinaison else: png_file = NamedTemporaryFile(prefix="kwapi", suffix=".png").name if zip_file: #Force temporary name png_file = NamedTemporaryFile(prefix="kwapi", suffix=".png").name # Get the file from cache if cachable and os.path.exists(png_file) and os.path.getmtime(png_file) > \ time.time() - scales[scale][0]['resolution']: return png_file else: return build_graph_energy(start, end, probes_uid, probes, summary, cachable, png_file, scale)