Ejemplo n.º 1
0
    def get_prom_data(self, res_id):
        """prometheus数据
        """
        end_at = int(time.time()) * 1000
        start_at = end_at - 60 * 10 * 1000

        metric_data = prometheus.get_node_cpu_usage(res_id, start_at, end_at)
        if metric_data:
            cpu_metrics = metric_data[-1]['usage']
        else:
            cpu_metrics = 0

        metric_data = prometheus.get_node_disk_io_utils(
            res_id, start_at, end_at)
        if metric_data:
            io_metrics = metric_data[-1]['usage']
        else:
            io_metrics = 0

        metric_data = prometheus.get_node_memory_usage(res_id, start_at,
                                                       end_at)
        if metric_data:
            mem_metrics = normalize_metric(metric_data[-1]['used'] * 100.0 /
                                           metric_data[-1]['total'])
        else:
            mem_metrics = 0

        data = {'cpu': cpu_metrics, 'mem': mem_metrics, 'io': io_metrics}
        return data
Ejemplo n.º 2
0
 def overview(self, request, project_id, cluster_id):
     """节点列表快照数据
     """
     res_id = request.GET.get('res_id')
     cpu = prometheus.get_node_cpu_usage(cluster_id, res_id)
     mem = prometheus.get_node_memory_usage(cluster_id, res_id)
     diskio = prometheus.get_node_disk_io(cluster_id, res_id)
     data = {'mem': mem, 'io': diskio, 'cpu': cpu}
     return response.Response(data)
Ejemplo n.º 3
0
    def overview(self, request, project_id, cluster_id):
        """节点列表快照数据
        """
        data = self.get_validated_data(request)
        ip = data["res_id"]

        cpu_usage = prometheus.get_node_cpu_usage(cluster_id, ip)
        memory_usage = prometheus.get_node_memory_usage(cluster_id, ip)
        disk_usage = prometheus.get_node_disk_usage(cluster_id, ip)
        diskio_usage = prometheus.get_node_diskio_usage(cluster_id, ip)
        data = {
            "cpu_usage": cpu_usage,
            "memory_usage": memory_usage,
            "disk_usage": disk_usage,
            "diskio_usage": diskio_usage,
        }
        return response.Response(data)
Ejemplo n.º 4
0
    def get_prom_data(self, data):
        """prometheus数据"""
        _data = []
        if data['metric'] == 'io':
            metric_data = prometheus.get_node_diskio_usage(data['res_id'], data['start_at'], data['end_at'])
            _data = {'list': [{'device_name': '', 'metrics': metric_data}]}

        elif data['metric'] == 'cpu_summary':
            metric_data = prometheus.get_node_cpu_usage(data['res_id'], data['start_at'], data['end_at'])
            _data = {'list': metric_data}

        elif data['metric'] == 'net':
            metric_data = prometheus.get_node_network_usage(data['res_id'], data['start_at'], data['end_at'])
            _data = {'list': [{'device_name': '', 'metrics': metric_data}]}

        elif data['metric'] == 'mem':
            metric_data = prometheus.get_node_memory_usage(data['res_id'], data['start_at'], data['end_at'])
            _data = {'list': metric_data}
        return _data