示例#1
0
    def get(self, request, *args, **kwargs):
        qs = request.GET
        node_name = qs.get("node_name")
        plugin_name = qs.get("plugin_name")
        param_name = qs.get("param_name")
        time_from = qs.get("time_from")
        time_to = qs.get("time_to")
        selected_time = qs.get("selected_time")

        param_info = \
        ParamInfo.objects(plugin_name=plugin_name, param_name=param_name)[0]
        filter = {
            'node': node_name,
            'plugin': plugin_name,
            'param': param_name,
            'stamp__lt': time_to,
            'stamp__gt': time_from,
        }
        print "filter['time_to']: ", filter['stamp__lt']
        print "type: ", type(filter['stamp__gt'])
        # count = MonitoringNodesData.objects(**filter).count()


        metric = []
        if 'pie_chart' in param_info.graph_types:
            data = MonitoringNodesData.objects(**filter)[0].data
            param_key = data.keys()[0]
            for k, v in data[param_key].items():
                if k != 'percent':
                    metric.append({'value': v, 'sector_name': k})
            return Response({
                'graph_types': param_info.graph_types,
                'graph_name': param_key,
                'axis_y': param_info.axis_y_title,
                'axis_x': param_info.axis_x_title,
                'data': metric
            })

        if 'line_chart' in param_info.graph_types:
            for data in MonitoringNodesData.objects(**filter):
                metric.append({'value': data.data[param_name],
                               'timestamp': data.stamp})

        if metric and param_info:
            return Response({
                'graph_types': param_info.graph_types,
                'graph_name': param_info.param_name,
                'axis_y': param_info.axis_y_title,
                'axis_x': param_info.axis_x_title,
                'data': metric
            })

        return Response({
            'result': 'error',
            'code': 1
        })
 def handle(self):
     selected_node = self.form_data['select_node']
     node = NodeInfo.objects(node_name=selected_node).first()
     for plugin in node.enabled_plugins:
         for param in ParamInfo.objects(plugin_name=plugin):
             data = {
                 'node': node.node_name,
                 'ip': node.node_ip,
                 'plugin': plugin,
                 'param': param.param_name,
                 'timeout': 0
             }
             monitoring_info = MonitoringInfo(**data)
             monitoring_info.save()
     return True
示例#3
0
    def get(self, request, *args, **kwargs):
        plugins_render = []

        plugins = PluginInfo.objects()
        for plugin in plugins:
            new_params = []
            params = ParamInfo.objects(plugin_name=plugin.plugin_name)
            for param in params:
                new_params.append({
                    'name': param.param_name,
                    'description': param.description,
                })
            plugins_render.append({
                'name': plugin.plugin_name,
                'description': plugin.description,
                'params_info': new_params
            })
        return render(request, self.template_name, {'plugins': plugins_render})
示例#4
0
    def get(self, request, *args, **kwargs):
        graphs_info = []
        node_name = kwargs.get('node_name')
        node_plugins = NodeInfo.objects.get(node_name=node_name).enabled_plugins

        id = 1
        print 'node_plugins: ', node_plugins
        for plugin in node_plugins:
            params = ParamInfo.objects(plugin_name=plugin)
            for param in params:
                graphs_info.append(
                        {
                            "id": "graph_id_" + str(id),
                            "plugin_name": plugin,
                            "node_name": node_name,
                            "param_name": param.param_name
                        }
                )
                id += 1
        return render(request, self.template_name, {'graphs_info': graphs_info})
示例#5
0
    def get(self, request, *args, **kwargs):
        graphs_info = []
        plugin_name = kwargs.get("plugin_name")
        # TODO: add 'try ... except'
        plugin_params = ParamInfo.objects(plugin_name=plugin_name)
        nodes = NodeInfo.objects()
        id = 1
        for node in nodes:
            if plugin_name in node.enabled_plugins:
                for param in plugin_params:
                    graphs_info.append(
                        {
                            "id": "graph_id_" + str(id),
                            "plugin_name": plugin_name,
                            "node_name": node.node_name,
                            "param_name": param.param_name,
                        }
                    )
                    id += 1

        return render(request, self.template_name, {"graphs_info": graphs_info})