当前位置: 首页>>代码示例>>Python>>正文


Python TmpGraph.get方法代码示例

本文整理汇总了Python中rrd.model.graph.TmpGraph.get方法的典型用法代码示例。如果您正苦于以下问题:Python TmpGraph.get方法的具体用法?Python TmpGraph.get怎么用?Python TmpGraph.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在rrd.model.graph.TmpGraph的用法示例。


在下文中一共展示了TmpGraph.get方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: charts

# 需要导入模块: from rrd.model.graph import TmpGraph [as 别名]
# 或者: from rrd.model.graph.TmpGraph import get [as 别名]
def charts():
    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))

    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())
开发者ID:codepiano,项目名称:dashboard,代码行数:62,代码来源:chart.py

示例2: multi_counters_chart_data

# 需要导入模块: from rrd.model.graph import TmpGraph [as 别名]
# 或者: from rrd.model.graph.TmpGraph import get [as 别名]
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,
        })

    series = []
    chart_series = create_chart_series(endpoint_counters, g.start, g.end, 'k', e)
    series = chart_series
    if g.comp_date > 0:
        comp_date_str = datetime.datetime.fromtimestamp(g.comp_date).strftime("%Y-%m-%d")
        comp_series = create_chart_series(endpoint_counters, g.comp_start, g.comp_end, 'k', e, comp_date_str + ":", g.duration)
        series.extend(comp_series)

    ret['series'] = series
    return json.dumps(ret)
开发者ID:modeyang,项目名称:dashboard,代码行数:44,代码来源:chart.py

示例3: multi_chart_data

# 需要导入模块: from rrd.model.graph import TmpGraph [as 别名]
# 或者: from rrd.model.graph.TmpGraph import get [as 别名]
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)
开发者ID:codepiano,项目名称:dashboard,代码行数:81,代码来源:chart.py

示例4: api_charts

# 需要导入模块: from rrd.model.graph import TmpGraph [as 别名]
# 或者: from rrd.model.graph.TmpGraph import get [as 别名]
def api_charts():
    ret = {
	"ok":True,
	"msg":"",
	"chart_ids":[],
	"chart_urls":[]
    }
    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 not g.id:
        abort(400, "no graph id given")

    tmp_graph = TmpGraph.get(g.id)
    if not tmp_graph:
        abort(400,"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))

    index = request.args.get("index",0)
     
    cur = int(index)
    chart_ids = []
    chart_urls = []
    max_load_graph = int(CHART_MAX_LOAD_GRAPH)
    if g.graph_type == GRAPH_TYPE_KEY:
        for x in endpoints[cur:cur+max_load_graph]:
            id_ = TmpGraph.add([x],counters)
            if not id_:
                continue
            p["id"] = id_
            chart_ids.append(int(id_))
            src = "/chart/k?" + urllib.urlencode(p)
            chart_urls.append(src)
    if g.graph_type == GRAPH_TYPE_HOST:
        for x in counters[cur:cur+max_load_graph]:
            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)
    
    ret['chart_ids'] = chart_ids
    ret['chart_urls'] = chart_urls
    return json.dumps(ret)	
开发者ID:masanmu,项目名称:dashboard,代码行数:63,代码来源:chart.py

示例5: dash_graph_edit

# 需要导入模块: from rrd.model.graph import TmpGraph [as 别名]
# 或者: from rrd.model.graph.TmpGraph import get [as 别名]
def dash_graph_edit(gid):
    error = ""
    is_tmp_graph = False
    graph = DashboardGraph.get(gid)

    all_screens = DashboardScreen.gets()
    top_screens = [x for x in all_screens if x.pid == '0']
    children = []
    for t in top_screens:
        children.append([x for x in all_screens if x.pid == t.id])

    if not graph:
        # 编辑临时 graph
        graph = TmpGraph.get(gid)
        graph = DashboardGraph.add('graph', graph.endpoints, graph.counters, 0)

        if not graph:
            abort(404, "no graph")
        is_tmp_graph = True

    if not is_tmp_graph:
        screen = DashboardScreen.get(graph.screen_id)
        if not screen:
            abort(404, "no screen")
    # pscreen = DashboardScreen.get(screen.pid)

    if request.method == "POST":
        ajax = request.form.get("ajax", "")
        screen_id = request.form.get("screen_id")
        title = request.form.get("title", "").strip()

        hosts = request.form.get("hosts", "").strip()
        hosts = hosts and hosts.split("\n") or []
        hosts = [x.strip() for x in hosts]

        counters = request.form.get("counters", "").strip()
        counters = counters and counters.split("\n") or []
        counters = [x.strip() for x in counters]

        timespan = request.form.get("timespan", 3600)
        graph_type = request.form.get("graph_type", 'h')
        method = request.form.get("method", '').upper()
        position = request.form.get("position", 0)

        if is_tmp_graph:  # 如果是临时graph修改之后就添加进去
            graph = DashboardGraph.add(title, hosts, counters, screen_id,
                                       timespan, graph_type, method, position)
        else:
            graph = graph.update(title, hosts, counters, screen_id,
                                 timespan, graph_type, method, position)

        error = u"修改成功了"
        if not ajax:
            options = qryOptions()
            return redirect('/screen/' + graph.screen_id)  # 重定向到对应的screen
            # return render_template("screen/graph_edit.html", config=config, **locals())
        else:
            return "ok"

    else:
        ajax = request.args.get("ajax", "")
        options = qryOptions()
        return render_template("screen/graph_edit.html", **locals())
开发者ID:1329555958,项目名称:dashboard,代码行数:65,代码来源:screen.py

示例6: multi_counters_chart_data

# 需要导入模块: from rrd.model.graph import TmpGraph [as 别名]
# 或者: from rrd.model.graph.TmpGraph import get [as 别名]
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)
#.........这里部分代码省略.........
开发者ID:itxx00,项目名称:dashboard,代码行数:103,代码来源:chart.py

示例7: chart_big

# 需要导入模块: from rrd.model.graph import TmpGraph [as 别名]
# 或者: from rrd.model.graph.TmpGraph import get [as 别名]
def chart_big():
    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)

    if not tmp_graph.counters[0]:
        abort(404, "no counter given")

    domeosid = g.domeosid
    if not domeosid:
        abort(400, "no domeos graph id given")

    domeos_graph = DomeosGraph.get(g.domeosid)
    if not domeos_graph:
        abort(404, "no domeos graph which id is %s" %g.domeosid)

    domeos_type = domeos_graph.type
    if not domeos_type:
        abort(400, "no domeos type of %s" %g.domeosid)

    domeos_data = domeos_graph.data

    chart_urls = []
    chart_ids = []
    if domeos_type == 'container':
        containers = json.loads(domeos_data)
        for container in containers:
            endpoint = []
            endpoint.append(container['hostname'])
            counter = []
            counter.append( tmp_graph.counters[0].split('/')[0] + '/id=' + container['containerId'])
            id_ = TmpGraph.add(endpoint, counter)
            if not id_:
                continue
            chart_ids.append(int(id_))
            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,
            }
            src = "/chart/h?" + urllib.urlencode(p)
            chart_urls.append(src)
    elif domeos_type == 'pod':
        pods = json.loads(domeos_data)
        for pod in pods:
            for container in pod['containers']:
                endpoint = []
                endpoint.append(container['hostname'])
                counter = []
                counter.append( tmp_graph.counters[0].split('/')[0] + '/id=' + container['containerId'])
                id_ = TmpGraph.add(endpoint, counter)
                if not id_:
                    continue
                chart_ids.append(int(id_))
                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,
                }
                src = "/chart/h?" + urllib.urlencode(p)
                chart_urls.append(src)

    return render_template("chart/big_ng.html", **locals())
开发者ID:lifuchina,项目名称:dashboard,代码行数:78,代码来源:chart.py


注:本文中的rrd.model.graph.TmpGraph.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。