示例#1
0
def Chart_Server_http(request, endpoint):
    """故障设备http服务请求数"""
    if request.method == 'GET':
        NET_TOTAL = ["ss.estab", "ss.timewait"]
        # endpoint="sr006.ct-zjhz-04.c4hcdn.cn"
        graph_data = []
        try:
            flow_counters = NET_TOTAL
            endpoint_counters = [{
                'endpoint': endpoint,
                'counter': i
            } for i in flow_counters]
            # graph_data 从query 取出的单个endpoint的信息(包含数据)
            query_result = rrdgraph.graph_query(endpoint_counters)
            # print len(query_result)
            for i in range(0, len(query_result)):
                x = query_result[i]
                # print x
                try:
                    xv = [[float(v["timestamp"] * 1000), (v["value"])]
                          for v in x["Values"]]
                    data_dict = {
                        "data": xv,
                        "name": "设备负载",
                        "cf": 'AVERAGE',
                        "endpoint": endpoint,
                        "counter": query_result[i]['counter'],
                    }
                    graph_data.append(data_dict)
                    # print graph_data
                except:
                    pass
            GD = json.dumps(graph_data)
        except:
            pass

    return render(request, 'view/alarm/chart_server_httpservices.html',
                  locals())
示例#2
0
def Chart_Big(request, endpoint_id):
    """节点流量"""
    if request.method == 'GET':

        endp = ENDPOINT_LIST[int(endpoint_id)]
        endpoint = ENDPOINT_LIST[int(endpoint_id)]
        flow_counters = FLOW_COUNTERS

        endpoint_counters = [{
            'endpoint': endpoint,
            'counter': i
        } for i in flow_counters]
        # graph_data 从query 取出的单个endpoint的信息(包含数据)
        query_result = rrdgraph.graph_query(endpoint_counters)
        #print graph_data
        graph_data = []

        for i in range(0, len(query_result)):
            x = query_result[i]
            try:
                xv = [[float(v["timestamp"] * 1000), v["value"]]
                      for v in x["Values"]]
                #print xv
                data_dict = {
                    "data": xv,
                    "name": query_result[i]["endpoint"],
                    "cf": 'AVERAGE',
                    "endpoint": query_result[i]["endpoint"],
                    "counter": query_result[i]["counter"],
                }
                graph_data.append(data_dict)
                # print graph_data
            except:
                pass
        GD = json.dumps(graph_data)
        # print type(graph_data)
    return render(request, 'view/chart_big.html', locals())
示例#3
0
def Chart_Server_network_error(request, endpoint):
    """故障设备网卡error变化"""
    if request.method == 'GET':
        """设备服务端口及状态"""
        openfalcon_sql = """
                        select c.grp_name from `host` a,grp_host b ,grp c  where a.id=b.host_id 
                        and b.grp_id=c.id and a.hostname='%s';""" % (endpoint)
        openfalcon = db_falcon.mysql_command(openfalcon_sql)
        a = [grp_name[0] for grp_name in openfalcon]
        # print ''.join(a)
        if ''.join(a).startswith('直播'):
            NET_TOTAL = [
                "net.if.out.dropped/iface=bond0",
                "net.if.in.dropped/iface=bond0",
                "net.if.out.errors/iface=bond0", "net.if.in.errors/iface=bond0"
            ]
            # endpoint="sr006.ct-zjhz-04.c4hcdn.cn"
            graph_data = []
            try:
                flow_counters = NET_TOTAL
                endpoint_counters = [{
                    'endpoint': endpoint,
                    'counter': i
                } for i in flow_counters]
                # graph_data 从query 取出的单个endpoint的信息(包含数据)
                query_result = rrdgraph.graph_query(endpoint_counters)
                # print len(query_result)
                for i in range(0, len(query_result)):
                    x = query_result[i]
                    # print x
                    try:
                        xv = [[float(v["timestamp"] * 1000), (v["value"])]
                              for v in x["Values"]]
                        data_dict = {
                            "data": xv,
                            "name": "设备负载",
                            "cf": 'AVERAGE',
                            "endpoint": endpoint,
                            "counter": query_result[i]['counter'],
                        }
                        graph_data.append(data_dict)
                        #print graph_data
                    except:
                        pass
                GD = json.dumps(graph_data)
            except:
                pass
        else:
            NET_TOTAL = [
                "net.if.out.dropped/iface=eth0",
                "net.if.in.dropped/iface=eth0", "net.if.out.errors/iface=eth0",
                "net.if.in.errors/iface=eth0"
            ]
            # endpoint="sr006.ct-zjhz-04.c4hcdn.cn"
            graph_data = []
            try:
                flow_counters = NET_TOTAL
                endpoint_counters = [{
                    'endpoint': endpoint,
                    'counter': i
                } for i in flow_counters]
                # graph_data 从query 取出的单个endpoint的信息(包含数据)
                query_result = rrdgraph.graph_query(endpoint_counters)
                # print len(query_result)
                for i in range(0, len(query_result)):
                    x = query_result[i]
                    # print x
                    try:
                        xv = [[float(v["timestamp"] * 1000), (v["value"])]
                              for v in x["Values"]]
                        data_dict = {
                            "data": xv,
                            "name": "设备负载",
                            "cf": 'AVERAGE',
                            "endpoint": endpoint,
                            "counter": query_result[i]['counter'],
                        }
                        graph_data.append(data_dict)
                        #print graph_data
                    except:
                        pass
                GD = json.dumps(graph_data)
            except:
                pass

    return render(request, 'view/alarm/chart_server_networkerror.html',
                  locals())