Esempio n. 1
0
def multi_chart_data():
    if not g.id:
        abort(400, "no graph id given")

    tmp_graph = TmpGraph.get(g.id)
    if not tmp_graph:
        abort(404, "no graph which id is %s" %g.id)

    counters = tmp_graph.counters
    if not counters:
        abort(400, "no counters of %s" %g.id)
    counters = sorted(set(counters))

    endpoints = tmp_graph.endpoints
    if not endpoints:
        abort(400, "no endpoints of %s, and tags:%s" %(g.id, g.tags))
    endpoints = sorted(set(endpoints))

    ret = {
        "units": "",
        "title": "",
        "series": []
    }

    endpoint_counters = []
    for e in endpoints:
        for c in counters:
            endpoint_counters.append({
                "endpoint": e,
                "counter": c,
            })
    query_result = graph_query(endpoint_counters, g.cf, g.start, g.end)

    series = []
    for i in range(0, len(query_result)):
        x = query_result[i]
        try:
            xv = [(v["timestamp"]*1000, v["value"]) for v in x["Values"]]
            serie = {
                    "data": xv,
                    "name": "%s %s" %(query_result[i]["endpoint"], query_result[i]["counter"]),
                    "cf": g.cf,
                    "endpoint": "",
                    "counter": "",
            }
            series.append(serie)
        except:
            pass

    sum_serie = {
            "data": [],
            "name": "sum",
            "cf": g.cf,
            "endpoint": "",
            "counter": "",
    }
    if g.sum == "on" or g.sumonly == "on":
        sum = []
        tmp_ts = []
        max_size = 0
        for serie in series:
            serie_vs = [x[1] for x in serie["data"]]
            if len(serie_vs) > max_size:
                max_size = len(serie_vs)
                tmp_ts = [x[0] for x in serie["data"]]
            sum = merge_list(sum, serie_vs)
        sum_serie_data = []
        for i in range(0, max_size):
            sum_serie_data.append((tmp_ts[i], sum[i]))
        sum_serie['data'] = sum_serie_data

        series.append(sum_serie)

    if g.sumonly == "on":
        ret['series'] = [sum_serie,]
    else:
        ret['series'] = series

    return json.dumps(ret)
Esempio n. 2
0
def multi_chart_data():
    if not g.id:
        abort(400, "no graph id given")

    tmp_graph = TmpGraph.get(g.id)
    if not tmp_graph:
        abort(404, "no graph which id is %s" % g.id)

    counters = tmp_graph.counters
    if not counters:
        abort(400, "no counters of %s" % g.id)
    counters = sorted(set(counters))

    endpoints = tmp_graph.endpoints
    if not endpoints:
        abort(400, "no endpoints of %s, and tags:%s" % (g.id, g.tags))
    endpoints = sorted(set(endpoints))

    ret = {"units": "", "title": "", "series": []}

    endpoint_counters = []
    for e in endpoints:
        for c in counters:
            endpoint_counters.append({
                "endpoint": e,
                "counter": c,
            })
    query_result = graph_query(endpoint_counters, g.cf, g.start, g.end)

    name_pre = ""
    if g.comp_date > 0:
        name_pre = "This Period: "
    series = []
    for i in range(0, len(query_result)):
        x = query_result[i]
        try:
            xv = [(v["timestamp"] * 1000, v["value"]) for v in x["Values"]]
            serie = {
                "data":
                xv,
                "name":
                "%s %s %s" % (name_pre, query_result[i]["endpoint"],
                              query_result[i]["counter"]),
                "cf":
                g.cf,
                "endpoint":
                "",
                "counter":
                "",
            }
            series.append(serie)
        except:
            pass

    sum_serie = {
        "data": [],
        "name": "%s %s" % (name_pre, "sum"),
        "cf": g.cf,
        "endpoint": "",
        "counter": "",
    }
    if g.sum == "on" or g.sumonly == "on":
        sum = []
        tmp_ts = []
        max_size = 0
        for serie in series:
            serie_vs = [x[1] for x in serie["data"]]
            if len(serie_vs) > max_size:
                max_size = len(serie_vs)
                tmp_ts = [x[0] for x in serie["data"]]
            sum = merge_list(sum, serie_vs)
        sum_serie_data = []
        for i in range(0, max_size):
            sum_serie_data.append((tmp_ts[i], sum[i]))
        sum_serie['data'] = sum_serie_data

        series.append(sum_serie)

    if g.sumonly == "on":
        ret['series'] = [
            sum_serie,
        ]
    else:
        ret['series'] = series

    if g.comp_date > 0:
        g.start = g.start - g.duration - 60
        g.end = g.end - g.duration + 60
        query_result = graph_query(endpoint_counters, g.cf, g.start, g.end)
        name_pre = "Last Period: "
        series_comp = []

        for i in range(0, len(query_result)):
            x = query_result[i]
            try:
                xv = [((v["timestamp"] + g.duration) * 1000, v["value"])
                      for v in x["Values"]]
                serie = {
                    "data":
                    xv,
                    "name":
                    "%s %s %s" % (name_pre, query_result[i]["endpoint"],
                                  query_result[i]["counter"]),
                    "cf":
                    g.cf,
                    "endpoint":
                    "",
                    "counter":
                    "",
                }
                series_comp.append(serie)
            except:
                pass

        sum_serie_comp = {
            "data": [],
            "name": "%s %s" % (name_pre, "sum"),
            "cf": g.cf,
            "endpoint": "",
            "counter": "",
        }
        if g.sum == "on" or g.sumonly == "on":
            sum = []
            tmp_ts = []
            max_size = 0
            for serie in series_comp:
                serie_vs = [x[1] for x in serie["data"]]
                if len(serie_vs) > max_size:
                    max_size = len(serie_vs)
                    tmp_ts = [x[0] for x in serie["data"]]
                sum = merge_list(sum, serie_vs)
            sum_serie_data = []
            for i in range(0, max_size):
                sum_serie_data.append((tmp_ts[i], sum[i]))
            sum_serie_comp['data'] = sum_serie_data

            series_comp.append(sum_serie_comp)

        if g.sumonly == "on":
            ret['series'] = [sum_serie, sum_serie_comp]
        else:
            series.extend(series_comp)
            ret['series'] = series

    return json.dumps(ret)
Esempio n. 3
0
            "data": [],
            "name": "%s %s" % (name_pre, "sum"),
            "cf": g.cf,
    }
    sum_serie.update(get_chart_type_sum_desc(chart_type, title_name))

    if g.sum == "on" or g.sumonly == "on":
        sum = []
        tmp_ts = []
        max_size = 0
        for serie in series:
            serie_vs = [x[1] for x in serie["data"]]
            if len(serie_vs) > max_size:
                max_size = len(serie_vs)
                tmp_ts = [x[0] for x in serie["data"]]
            sum = merge_list(sum, serie_vs)
        sum_serie_data = []
        for i in range(0, max_size):
            sum_serie_data.append((tmp_ts[i], sum[i]))
        sum_serie['data'] = sum_serie_data
        series.append(sum_serie)

    return [sum_serie] if g.sumonly == "on" else series


@app.route("/chart/h", methods=["GET"])
def multi_endpoints_chart_data():
    if not g.id:
        abort(400, "no graph id given")

    tmp_graph = TmpGraph.get(g.id)
Esempio n. 4
0
def multi_counters_chart_data():
    if not g.id:
        abort(400, "no graph id given")

    tmp_graph = TmpGraph.get(g.id)
    if not tmp_graph:
        abort(404, "no graph which id is %s" %g.id)

    counters = tmp_graph.counters
    if not counters:
        abort(400, "no counters of %s" %g.id)
    counters = sorted(set(counters))

    endpoints = tmp_graph.endpoints
    if not endpoints:
        abort(400, "no endpoints of %s" % g.id)
    endpoints = sorted(set(endpoints))

    ret = {
        "units": "",
        "title": "",
        "series": []
    }
    ret['title'] = endpoints[0]
    e = endpoints[0]
    endpoint_counters = []
    for c in counters:
        endpoint_counters.append({
            "endpoint": e,
            "counter": c,
        })

    query_result = graph_query(endpoint_counters, g.cf, g.start, g.end)

    series = []
    for i in range(0, len(query_result)):
        x = query_result[i]
        try:
            xv = [(v["timestamp"]*1000, v["value"]) for v in x["Values"]]
            serie = {
                    "data": xv,
                    "name": query_result[i]["counter"],
                    "cf": g.cf,
                    "endpoint": query_result[i]["endpoint"],
                    "counter": query_result[i]["counter"],
            }
            series.append(serie)
        except:
            pass

    sum_serie = {
            "data": [],
            "name": "sum",
            "cf": g.cf,
            "endpoint": e,
            "counter": "sum",
    }
    if g.sum == "on" or g.sumonly == "on":
        sum = []
        tmp_ts = []
        max_size = 0
        for serie in series:
            serie_vs = [x[1] for x in serie["data"]]
            if len(serie_vs) > max_size:
                max_size = len(serie_vs)
                tmp_ts = [x[0] for x in serie["data"]]
            sum = merge_list(sum, serie_vs)
        sum_serie_data = []
        for i in range(0, max_size):
            sum_serie_data.append((tmp_ts[i], sum[i]))
        sum_serie['data'] = sum_serie_data

        series.append(sum_serie)

    if g.sumonly == "on":
        ret['series'] = [sum_serie,]
    else:
        ret['series'] = series

    return json.dumps(ret)
Esempio n. 5
0
def multi_counters_chart_data():
    if not g.id:
        abort(400, "no graph id given")

    tmp_graph = TmpGraph.get(g.id)
    if not tmp_graph:
        abort(404, "no graph which id is %s" %g.id)

    counters = tmp_graph.counters
    if not counters:
        abort(400, "no counters of %s" %g.id)
    counters = sorted(set(counters))

    endpoints = tmp_graph.endpoints
    if not endpoints:
        abort(400, "no endpoints of %s" % g.id)
    endpoints = sorted(set(endpoints))

    ret = {
        "units": "",
        "title": "",
        "series": []
    }
    ret['title'] = endpoints[0]
    e = endpoints[0]
    endpoint_counters = []
    for c in counters:
        endpoint_counters.append({
            "endpoint": e,
            "counter": c,
        })

    query_result = graph_query(endpoint_counters, g.cf, g.start, g.end)

    name_pre = ""
    if g.comp_date > 0:
        name_pre = "This Period: "
    series = []
    for i in range(0, len(query_result)):
        x = query_result[i]
        try:
            xv = [(v["timestamp"]*1000, v["value"]) for v in x["Values"]]
            serie = {
                    "data": xv,
                    "name": "%s %s" % (name_pre, query_result[i]["counter"]),
                    "cf": g.cf,
                    "endpoint": query_result[i]["endpoint"],
                    "counter": query_result[i]["counter"],
            }
            series.append(serie)
        except:
            pass

    sum_serie = {
            "data": [],
            "name": "%s %s" % (name_pre, "sum"),
            "cf": g.cf,
            "endpoint": e,
            "counter": "sum",
    }
    if g.sum == "on" or g.sumonly == "on":
        sum = []
        tmp_ts = []
        max_size = 0
        for serie in series:
            serie_vs = [x[1] for x in serie["data"]]
            if len(serie_vs) > max_size:
                max_size = len(serie_vs)
                tmp_ts = [x[0] for x in serie["data"]]
            sum = merge_list(sum, serie_vs)
        sum_serie_data = []
        for i in range(0, max_size):
            sum_serie_data.append((tmp_ts[i], sum[i]))
        sum_serie['data'] = sum_serie_data

        series.append(sum_serie)

    if g.sumonly == "on":
        ret['series'] = [sum_serie,]
    else:
        ret['series'] = series

    if g.comp_date > 0:
        g.start = g.start - g.duration - 60
        g.end = g.end - g.duration + 60
        query_result = graph_query(endpoint_counters, g.cf, g.start, g.end)
        name_pre = "Last Period: "
        series_comp = []
        for i in range(0, len(query_result)):
            x = query_result[i]
            try:
                xv = [((v["timestamp"]+g.duration)*1000, v["value"]) for v in x["Values"]]
                serie = {
                        "data": xv,
                        "name": "%s %s" % (name_pre, query_result[i]["counter"]),
                        "cf": g.cf,
                        "endpoint": query_result[i]["endpoint"],
                        "counter": query_result[i]["counter"],
                }
                series_comp.append(serie)
            except:
                pass

        sum_serie_comp = {
                "data": [],
                "name": "%s %s" % (name_pre, "sum"),
                "cf": g.cf,
                "endpoint": e,
                "counter": "sum",
        }
        if g.sum == "on" or g.sumonly == "on":
            sum = []
            tmp_ts = []
            max_size = 0
            for serie in series_comp:
                serie_vs = [x[1] for x in serie["data"]]
                if len(serie_vs) > max_size:
                    max_size = len(serie_vs)
                    tmp_ts = [x[0] for x in serie["data"]]
                sum = merge_list(sum, serie_vs)
            sum_serie_data = []
            for i in range(0, max_size):
                sum_serie_data.append((tmp_ts[i], sum[i]))
            sum_serie_comp['data'] = sum_serie_data

            series_comp.append(sum_serie_comp)

        if g.sumonly == "on":
            ret['series'] = [sum_serie,sum_serie_comp]
        else:
            series.extend(series_comp)
            ret['series'] = series

    return json.dumps(ret)
Esempio n. 6
0
def multi_endpoints_chart_data():
    if not g.id:
        abort(400, "no graph id given")

    tmp_graph = TmpGraph.get(g.id)
    if not tmp_graph:
        abort(404, "no graph which id is %s" % g.id)

    counters = tmp_graph.counters
    if not counters:
        abort(400, "no counters of %s" % g.id)
    counters = sorted(set(counters))

    endpoints = tmp_graph.endpoints
    if not endpoints:
        abort(400, "no endpoints of %s" % (g.id, ))
    endpoints = sorted(set(endpoints))

    ret = {"units": "", "title": "", "series": []}
    ret['title'] = counters[0]
    c = counters[0]
    endpoint_counters = []
    for e in endpoints:
        endpoint_counters.append({
            "endpoint": e,
            "counter": c,
        })

    if g.comp_date > 0:
        today = datetime.datetime.today()
        today_start = int(time.mktime(today.date().timetuple()))
        today_end = int(
            time.mktime(
                datetime.datetime(today.year, today.month, today.day, 23, 59,
                                  59).timetuple()))
        start = int(request.args.get("start") or 0)
        end = int(request.args.get("end") or 0)
        if start == 0 and end == 0:
            g.start = today_start
            g.end = today_end
        lt = time.localtime(g.start)
        day_start = int(
            time.mktime(
                datetime.datetime(lt.tm_year, lt.tm_mon, lt.tm_mday, 00, 00,
                                  00).timetuple()))
        duration = g.start - g.comp_date - (g.start - day_start)

    query_result = graph_history(endpoints, counters, g.cf, g.start, g.end)

    series = []
    for i in range(0, len(query_result)):
        x = query_result[i]
        try:
            xv = [(v["timestamp"] * 1000, v["value"]) for v in x["Values"]]
            serie = {
                "data": xv,
                "name": query_result[i]["endpoint"],
                "cf": g.cf,
                "endpoint": query_result[i]["endpoint"],
                "counter": query_result[i]["counter"],
            }
            if g.comp_date > 0:
                serie["name"] = "This-Period: " + query_result[i]["endpoint"]
            series.append(serie)
        except:
            pass

    sum_serie = {
        "data": [],
        "name": "sum",
        "cf": g.cf,
        "endpoint": "sum",
        "counter": c,
    }
    if g.comp_date > 0:
        sum_serie["name"] = "This-Period: sum"

    if g.sum == "on" or g.sumonly == "on":
        sum = []
        tmp_ts = []
        max_size = 0
        for serie in series:
            serie_vs = [x[1] for x in serie["data"]]
            if len(serie_vs) > max_size:
                max_size = len(serie_vs)
                tmp_ts = [x[0] for x in serie["data"]]
            sum = merge_list(sum, serie_vs)
        sum_serie_data = []
        for i in range(0, max_size):
            sum_serie_data.append((tmp_ts[i], sum[i]))
        sum_serie['data'] = sum_serie_data

        series.append(sum_serie)

    if g.sumonly == "on":
        ret['series'] = [
            sum_serie,
        ]
    else:
        ret['series'] = series

    if g.comp_date > 0:
        series_comp = []
        g.start = g.start - duration - 60
        g.end = g.end - duration + 60
        query_result = graph_history(endpoints, counters, g.cf, g.start, g.end)
        for i in range(0, len(query_result)):
            x = query_result[i]
            try:
                xv = [((v["timestamp"] + duration) * 1000, v["value"])
                      for v in x["Values"]]
                serie = {
                    "data": xv,
                    "name": "Last-Period: " + query_result[i]["endpoint"],
                    "cf": g.cf,
                    "endpoint": query_result[i]["endpoint"],
                    "counter": query_result[i]["counter"],
                }
                series_comp.append(serie)
            except:
                pass
        sum_serie_comp = {
            "data": [],
            "name": "Last-Period: sum",
            "cf": g.cf,
            "endpoint": "sum",
            "counter": c,
        }

        if g.sum == "on" or g.sumonly == "on":
            sum = []
            tmp_ts = []
            max_size = 0
            for serie in series_comp:
                serie_vs = [x[1] for x in serie["data"]]
                if len(serie_vs) > max_size:
                    max_size = len(serie_vs)
                    tmp_ts = [x[0] for x in serie["data"]]
                sum = merge_list(sum, serie_vs)
            sum_serie_data = []
            for i in range(0, max_size):
                sum_serie_data.append((tmp_ts[i], sum[i]))
            sum_serie_comp['data'] = sum_serie_data

            series_comp.append(sum_serie_comp)

        if g.sumonly == "on":
            ret['series'] = [sum_serie, sum_serie_comp]
        else:
            series.extend(series_comp)
            ret['series'] = series

    return json.dumps(ret)
Esempio n. 7
0
def multi_endpoints_chart_data():
    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))

    ret = {
        "units": "",
        "title": "",
        "series": []
    }

    c = counters[0]
    ret['title'] = c
    query_result = graph_history(endpoints, counters[:1], g.cf, g.start, g.end)

    series = []
    for i in range(0, len(query_result)):
        x = query_result[i]
        try:
            xv = [(v["timestamp"] * 1000, v["value"]) for v in x["Values"]]
            serie = {
                "data": xv,
                "name": query_result[i]["endpoint"],
                "cf": g.cf,
                "endpoint": query_result[i]["endpoint"],
                "counter": query_result[i]["counter"],
            }
            series.append(serie)
        except:
            pass

    # 通过查看dashboard_grap判断是否存在环比看图
    if g.dgid:
        dg = DashboardGraph.get(g.dgid)
        if dg.relativeday > 0:
            query_result = graph_history(endpoints[:1], counters, g.cf, g.start - dg.relativeday * 24 * 3600,
                                         g.end - dg.relativeday * 24 * 3600)
            for i in range(0, len(query_result)):
                x = query_result[i]
                try:
                    xv = [((v["timestamp"] + dg.relativeday * 24 * 3600)* 1000, v["value"]) for v in x["Values"]]
                    serie = {
                        "data": xv,
                        "name": u"[环比:" + str(dg.relativeday) + u"天]" + query_result[i]["endpoint"],
                        "cf": g.cf,
                        "endpoint": query_result[i]["endpoint"],
                        "counter": query_result[i]["counter"],
                    }
                    series.append(serie)
                except:
                    print(traceback.format_exc())
                    pass

    sum_serie = {
        "data": [],
        "name": "sum",
        "cf": g.cf,
        "endpoint": "sum",
        "counter": c,
    }
    if g.sum == "on" or g.sumonly == "on":
        sum = []
        tmp_ts = []
        max_size = 0
        for serie in series:
            serie_vs = [x[1] for x in serie["data"]]
            if len(serie_vs) > max_size:
                max_size = len(serie_vs)
                tmp_ts = [x[0] for x in serie["data"]]
            sum = merge_list(sum, serie_vs)
        sum_serie_data = []
        for i in range(0, max_size):
            sum_serie_data.append((tmp_ts[i], sum[i]))
        sum_serie['data'] = sum_serie_data

        series.append(sum_serie)

    if g.sumonly == "on":
        ret['series'] = [sum_serie, ]
    else:
        ret['series'] = series

    return json.dumps(ret)
Esempio n. 8
0
def multi_endpoints_chart_data():
    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))

    ret = {
        "units": "",
        "title": "",
        "series": []
   }

    c = counters[0]
    ret['title'] = c
    query_result = graph_history(endpoints, counters[:1], g.cf, g.start, g.end)

    series = []
    for i in range(0, len(query_result)):
        x = query_result[i]
        try:
            xv = [(v["timestamp"]*1000, v["value"]) for v in x["Values"]]
            serie = {
                    "data": xv,
                    "name": query_result[i]["endpoint"],
                    "cf": g.cf,
                    "endpoint": query_result[i]["endpoint"],
                    "counter": query_result[i]["counter"],
                    }
            series.append(serie)
        except:
            pass

    sum_serie = {
            "data": [],
            "name": "sum",
            "cf": g.cf,
            "endpoint": "sum",
            "counter": c,
            }
    if g.sum == "on" or g.sumonly == "on":
        sum = []
        tmp_ts = []
        max_size = 0
        for serie in series:
            serie_vs = [x[1] for x in serie["data"]]
            if len(serie_vs) > max_size:
                max_size = len(serie_vs)
                tmp_ts = [x[0] for x in serie["data"]]
            sum = merge_list(sum, serie_vs)
        sum_serie_data = []
        for i in range(0, max_size):
            sum_serie_data.append((tmp_ts[i], sum[i]))
        sum_serie['data'] = sum_serie_data

        series.append(sum_serie)

    if g.sumonly == "on":
        ret['series'] = [sum_serie,]
    else:
        ret['series'] = series

    return json.dumps(ret)
Esempio n. 9
0
def multi_endpoints_chart_data():
    if not g.id:
        abort(400, "no graph id given")
    log.info("/chart/h_for_id:%s" % g.id)
    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))

    ret = {"units": "", "title": "", "series": []}

    c = counters[0]
    ret['title'] = c
    # log.debug("start_call_graph_history for j :%s"%(str(ret)))
    query_result = graph_history(endpoints, counters[:1], g.cf, g.start, g.end)
    # log.debug("query_result_%s"%str(query_result))
    series = []
    for i in range(0, len(query_result)):
        x = query_result[i]
        try:
            xv = [(v["timestamp"] * 1000, v["value"]) for v in x["Values"]]
            serie = {
                "data": xv,
                "name": query_result[i]["endpoint"],
                "cf": g.cf,
                "endpoint": query_result[i]["endpoint"],
                "counter": query_result[i]["counter"],
            }
            series.append(serie)
        except:
            pass

    sum_serie = {
        "data": [],
        "name": "sum",
        "cf": g.cf,
        "endpoint": "sum",
        "counter": c,
    }
    if g.sum == "on" or g.sumonly == "on":
        sum = []
        tmp_ts = []
        max_size = 0
        for serie in series:
            serie_vs = [x[1] for x in serie["data"]]
            if len(serie_vs) > max_size:
                max_size = len(serie_vs)
                tmp_ts = [x[0] for x in serie["data"]]
            sum = merge_list(sum, serie_vs)
        sum_serie_data = []
        for i in range(0, max_size):
            sum_serie_data.append((tmp_ts[i], sum[i]))
        sum_serie['data'] = sum_serie_data

        series.append(sum_serie)

    if g.sumonly == "on":
        ret['series'] = [
            sum_serie,
        ]
    else:
        ret['series'] = series

    return json.dumps(ret)
Esempio n. 10
0
def multi_counters_chart_data():
    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))

    print today_date_str(), "/chart/k_counters_endpoints", endpoints, counters
    ret = {"units": "", "title": "", "series": []}
    e = endpoints[0]
    ret['title'] = e

    query_result = graph_history(endpoints[:1], counters, g.cf, g.start, g.end)
    print today_date_str(), "/chart/k_graph_history", query_result
    series = []
    for i in range(0, len(query_result)):
        x = query_result[i]
        try:
            xv = [(v["timestamp"] * 1000, v["value"]) for v in x["Values"]]
            serie = {
                "data": xv,
                "name": query_result[i]["counter"],
                "cf": g.cf,
                "endpoint": query_result[i]["endpoint"],
                "counter": query_result[i]["counter"],
            }
            series.append(serie)
        except:
            pass
    print today_date_str(), "/chart/k_end_for"
    sum_serie = {
        "data": [],
        "name": "sum",
        "cf": g.cf,
        "endpoint": e,
        "counter": "sum",
    }
    if g.sum == "on" or g.sumonly == "on":
        sum = []
        tmp_ts = []
        max_size = 0
        for serie in series:
            serie_vs = [x[1] for x in serie["data"]]
            if len(serie_vs) > max_size:
                max_size = len(serie_vs)
                tmp_ts = [x[0] for x in serie["data"]]
            sum = merge_list(sum, serie_vs)
        sum_serie_data = []
        for i in range(0, max_size):
            sum_serie_data.append((tmp_ts[i], sum[i]))
        sum_serie['data'] = sum_serie_data

        series.append(sum_serie)

    if g.sumonly == "on":
        ret['series'] = [
            sum_serie,
        ]
    else:
        ret['series'] = series

    print today_date_str(), "/chart/k_json.dumps",
    return json.dumps(ret)