def charts(): if not g.id: abort(400, "no graph id given") j = TmpGraph.get(g.id) if not j: abort(400, "no such tmp_graph where id=%s" % g.id) counters = j.counters if not counters: abort(400, "no counters of %s" % g.id) counters = sorted(set(counters)) endpoints = j.endpoints if not endpoints: abort(400, "no endpoints of %s" % g.id) endpoints = sorted(set(endpoints)) chart_urls = [] chart_ids = [] p = { "id": "", "legend": g.legend, "cf": g.cf, "sum": g.sum, "graph_type": g.graph_type, "nav_header": g.nav_header, "start": g.start, "end": g.end, "comp_date": g.comp_date, } if g.graph_type == GRAPH_TYPE_KEY: for x in endpoints: id_ = TmpGraph.add([x], counters) if not id_: continue p["id"] = id_ chart_ids.append(int(id_)) src = "/chart/h?" + urllib.urlencode(p) chart_urls.append(src) elif g.graph_type == GRAPH_TYPE_HOST: for x in counters: id_ = TmpGraph.add(endpoints, [x]) if not id_: continue p["id"] = id_ chart_ids.append(int(id_)) src = "/chart/h?" + urllib.urlencode(p) chart_urls.append(src) else: id_ = TmpGraph.add(endpoints, counters) if id_: p["id"] = id_ chart_ids.append(int(id_)) src = "/chart/a?" + urllib.urlencode(p) chart_urls.append(src) return render_template("chart/multi_ng.html", **locals())
def charts(): if not g.id: abort(400, "no graph id given") j = TmpGraph.get(g.id) if not j: abort(400, "no such tmp_graph where id=%s" %g.id) counters = j.counters if not counters: abort(400, "no counters of %s" %g.id) counters = sorted(set(counters)) endpoints = j.endpoints if not endpoints: abort(400, "no endpoints of %s" %g.id) endpoints = sorted(set(endpoints)) chart_urls = [] chart_ids = [] p = { "id": "", "legend": g.legend, "cf": g.cf, "sum": g.sum, "graph_type": g.graph_type, "nav_header": g.nav_header, "start": g.start, "end": g.end, } if g.graph_type == GRAPH_TYPE_KEY: for x in endpoints: id_ = TmpGraph.add([x], counters) if not id_: continue p["id"] = id_ chart_ids.append(int(id_)) src = "/chart/h?" + urllib.urlencode(p) chart_urls.append(src) elif g.graph_type == GRAPH_TYPE_HOST: for x in counters: id_ = TmpGraph.add(endpoints, [x]) if not id_: continue p["id"] = id_ chart_ids.append(int(id_)) src = "/chart/h?" + urllib.urlencode(p) chart_urls.append(src) else: id_ = TmpGraph.add(endpoints, counters) if id_: p["id"] = id_ chart_ids.append(int(id_)) src = "/chart/a?" + urllib.urlencode(p) chart_urls.append(src) return render_template("chart/multi_ng.html", **locals())
def _generate_graph_urls(graph, counters, endpoint_list, start, end): ret_graphs = [] if graph.graph_type == 'h': for c in counters: tmp_graph_id = TmpGraph.add(endpoint_list, [c,]) if not tmp_graph_id: break new_g = copy.deepcopy(graph) new_g.counters = c if end: new_g.src = '''/chart/h?id=%s&start=%s&end=%s''' %(tmp_graph_id, start or (0-graph.timespan), end) else: new_g.src = '''/chart/h?id=%s&start=%s''' %(tmp_graph_id, start or (0-graph.timespan)) if graph.method == 'SUM': new_g.src += "&sum=on" else: new_g.src += "&cf=%s" %graph.method ret_graphs.append(new_g) elif graph.graph_type=='k': for e in endpoint_list: tmp_graph_id = TmpGraph.add([e,], counters) if not tmp_graph_id: break new_g = copy.deepcopy(graph) new_g.hosts = e if end: new_g.src = '''/chart/k?id=%s&start=%s&end=%s''' %(tmp_graph_id, start or (0-graph.timespan), end) else: new_g.src = '''/chart/k?id=%s&start=%s''' %(tmp_graph_id, start or (0-graph.timespan)) if graph.method == 'SUM': new_g.src += "&sum=on" else: new_g.src += "&cf=%s" %graph.method ret_graphs.append(new_g) else: #组合视角 tmp_graph_id = TmpGraph.add(endpoint_list, counters) if not tmp_graph_id: return [] new_g = copy.deepcopy(graph) if end: new_g.src = '''/chart/a?id=%s&start=%s&end=%s''' %(tmp_graph_id, start or (0-graph.timespan), end) else: new_g.src = '''/chart/a?id=%s&start=%s''' %(tmp_graph_id, start or (0-graph.timespan)) if graph.method == 'SUM': new_g.src += "&sum=on" else: new_g.src += "&cf=%s" %graph.method ret_graphs.append(new_g) return ret_graphs
def _generate_graph_urls(graph, counters, endpoint_list, start, end): ret_graphs = [] if graph.graph_type == 'h': for c in counters: tmp_graph_id = TmpGraph.add(endpoint_list, [c,]) if not tmp_graph_id: break new_g = copy.deepcopy(graph) new_g.counters = c if end: new_g.src = '''/chart/h?id=%s&start=%s&end=%s''' %(tmp_graph_id, start or (0-graph.timespan), end) else: new_g.src = '''/chart/h?id=%s&start=%s''' %(tmp_graph_id, start or (0-graph.timespan)) if graph.method == 'SUM': new_g.src += "&sum=on" else: new_g.src += "&cf=%s" %graph.method ret_graphs.append(new_g) elif graph.graph_type=='k': for e in endpoint_list: tmp_graph_id = TmpGraph.add([e,], counters) if not tmp_graph_id: break new_g = copy.deepcopy(graph) new_g.hosts = e if end: new_g.src = '''/chart/k?id=%s&start=%s&end=%s''' %(tmp_graph_id, start or (0-graph.timespan), end) else: new_g.src = '''/chart/k?id=%s&start=%s''' %(tmp_graph_id, start or (0-graph.timespan)) if graph.method == 'SUM': new_g.src += "&sum=on" else: new_g.src += "&cf=%s" %graph.method ret_graphs.append(new_g) else: #组合视角 tmp_graph_id = TmpGraph.add(endpoint_list, counters) if not tmp_graph_id: return [] new_g = copy.deepcopy(graph) if end: new_g.src = '''/chart/a?id=%s&start=%s&end=%s''' %(tmp_graph_id, start or (0-graph.timespan), end) else: new_g.src = '''/chart/a?id=%s&start=%s''' %(tmp_graph_id, start or (0-graph.timespan)) if graph.method == 'SUM': new_g.src += "&sum=on" else: new_g.src += "&cf=%s" %graph.method ret_graphs.append(new_g) return ret_graphs
def chart(): endpoints = request.form.getlist("endpoints[]") or [] counters = request.form.getlist("counters[]") or [] graph_type = request.form.get("graph_type") or GRAPH_TYPE_HOST id_ = TmpGraph.add(endpoints, counters) ret = { "ok": False, "id": id_, "params": { "graph_type": graph_type, }, } if id_: ret['ok'] = True return json.dumps(ret)
def chart(): endpoints = request.form.getlist("endpoints[]") or [] counters = request.form.getlist("counters[]") or [] graph_type = request.form.get("graph_type") or GRAPH_TYPE_HOST id_ = TmpGraph.add(endpoints, counters) ret = { "ok": False, "id": id_, "params": { "graph_type": graph_type, }, } if id_: ret['ok'] = True return json.dumps(ret)