实现prometheus+grafana的监控部署

news2024/10/26 1:56:01

直接贴部署用的文件信息了

kubectl label node xxx monitoring=true


创建命名空间
 

kubectl create ns monitoring

部署operator

kubectl apply -f operator-rbac.yml
kubectl apply -f operator-dp.yml
kubectl apply -f operator-crd.yml


 # 定义node-export

kubectl apply -f ./node-exporter/node-exporter-sa.yml
kubectl apply -f ./node-exporter/node-exporter-rbac.yml
kubectl apply -f ./node-exporter/node-exporter-svc.yml
kubectl apply -f ./node-exporter/node-exporter-ds.yml

 # 自定义配置文件,定义显示方式

kubectl apply -f ./grafana/pv-pvc-hostpath.yml
kubectl apply -f ./grafana/grafana-sa.yml
kubectl apply -f ./grafana/grafana-source.yml
kubectl apply -f ./grafana/grafana-datasources.yml
kubectl apply -f ./grafana/grafana-admin-secret.yml
kubectl apply -f ./grafana/grafana-svc.yml


 # 创建配置conifgmap
 

kubectl create configmap grafana-config --from-file=./grafana/grafana.ini --namespace=monitoring
kubectl create configmap all-grafana-dashboards --from-file=./grafana/dashboard --namespace=monitoring


kubectl apply -f ./grafana/grafana-dp.yml
kubectl apply -f ./service-discovery/kube-controller-manager-svc.yml
kubectl apply -f ./service-discovery/kube-scheduler-svc.yml

 # 自定义配置文件,定义收集和报警规则
 

kubectl apply -f ./prometheus/prometheus-secret.yml
kubectl apply -f ./prometheus/prometheus-rules.yml
kubectl apply -f ./prometheus/prometheus-rbac.yml
kubectl apply -f ./prometheus/prometheus-svc.yml

# prometheus-operator  部署成功后才能创建成功
 

kubectl apply -f ./prometheus/pv-pvc-hostpath.yaml
kubectl apply -f ./prometheus/prometheus-main.yml

 # 监控目标,lable必须是k8s-app  因为prometheus是按这个查找的。不然prometheus采集不了该

kubectl apply -f ./servicemonitor/alertmanager-sm.yml
kubectl apply -f ./servicemonitor/coredns-sm.yml
kubectl apply -f ./servicemonitor/kube-apiserver-sm.yml
kubectl apply -f ./servicemonitor/kube-controller-manager-sm.yml
kubectl apply -f ./servicemonitor/kube-scheduler-sm.yml
kubectl apply -f ./servicemonitor/kubelet-sm.yml
kubectl apply -f ./servicemonitor/kubestate-metrics-sm.yml
kubectl apply -f ./servicemonitor/node-exporter-sm.yml
kubectl apply -f ./servicemonitor/prometheus-operator-sm.yml
kubectl apply -f ./servicemonitor/prometheus-sm.yml
kubectl apply -f ./servicemonitor/pushgateway-sm.yml

# prometheus-adapter  部署

kubectl apply -f ./prometheus_adapter/metric_rule.yaml
kubectl apply -f ./prometheus_adapter/prometheus_adapter.yaml

受限于篇幅就不张贴部署脚本内容,详情请参见

GitHub - chenrui2200/prometheus_k8s_install

创建出进监控pod

node_exporterprometheus_k8s 是在 Kubernetes 环境中监控和收集指标的两个重要组件。它们之间有着密切的关系,以下是它们的详细讲解及相互关系。

Node Exporter

  • 定义: node_exporter 是 Prometheus 官方提供的一个工具,用于收集和暴露操作系统及硬件的性能指标。这些指标包括 CPU、内存、磁盘、网络等系统级别的性能数据。

  • 功能:

    • 它运行在每个节点上,监控该节点的系统资源使用情况。
    • 提供的指标格式符合 Prometheus 的要求,因此可以直接被 Prometheus 抓取。
  • 使用场景:

    • 适用于监控物理机、虚拟机或 Kubernetes 节点的基础设施健康状态。

Prometheus K8s

  • 定义: prometheus_k8s 是一个 Prometheus 实例,专门用于在 Kubernetes 集群中监控 Kubernetes 资源及其运行的应用。

  • 功能:

    • 通过 Kubernetes 的 API,自动发现集群中的服务和容器,并抓取它们暴露的指标。
    • 可以监控 Kubernetes 组件(如 kube-apiserver、kube-scheduler、kube-controller-manager)及各个应用程序的性能。
  • 使用场景:

    • 适用于监控整个 Kubernetes 集群的健康状况和性能。

二者的关系

  1. 数据来源:

    • node_exporter 收集每个节点的系统性能指标,然后 Prometheus 可以抓取这些指标。
    • prometheus_k8s 则从 Kubernetes 中的其他组件和应用程序收集指标。
  2. 监控层次:

    • node_exporter 主要关注底层硬件和操作系统级别的监控。
    • prometheus_k8s 关注 Kubernetes 资源和应用的监控,包括 Pods、服务和其它 Kubernetes 对象。
  3. 集成:

    • 在 Kubernetes 环境中,通常会在每个节点上运行 node_exporter,并配置 prometheus_k8s 来定期抓取 node_exporter 的指标,这样就能实现对节点性能的全面监控。

node_exporterprometheus_k8s 是相辅相成的。node_exporter 提供了基础设施级别的监控,而 prometheus_k8s 则补充了 Kubernetes 资源和应用的监控。结合使用这两个组件,能够实现对整个系统的全面监控,帮助运维人员及时发现和解决问题。

查看前端展示

python实现prometheus客户端

import json, datetime, time
import requests
import pysnooper


class Prometheus():

    def __init__(self, host=''):
        #  '/api/v1/query_range'    查看范围数据
        #  '/api/v1/query'    瞬时数据查询
        self.host = host
        self.query_path = 'http://%s/api/v1/query' % self.host
        self.query_range_path = 'http://%s/api/v1/query_range' % self.host

    # @pysnooper.snoop()
    def get_istio_service_metric(self, namespace):
        service_metric = {
            "qps": {},
            "gpu": {},
            "memory": {},
            "cpu": {}
        }
        # qps请求
        mem_expr = 'sum by (destination_workload,response_code) (irate(istio_requests_total{destination_service_namespace="%s"}[1m]))' % (namespace,)
        # print(mem_expr)
        params = {
            'query': mem_expr,
            'start': int(time.time())-300,
            'end': int(time.time()),
            'step': "1m",  # 运行小于1分钟的,将不会被采集到
            # 'timeout':"30s"
        }
        print(params)

        try:
            res = requests.get(url=self.query_range_path, params=params)
            metrics = json.loads(res.content.decode('utf8', 'ignore'))
            if metrics['status'] == 'success':
                metrics = metrics['data']['result']
                if metrics:
                    for service in metrics:
                        service_name = service['metric']['destination_workload']
                        if service_name not in service_metric['qps']:
                            service_metric['qps'][service_name] = {}
                        service_metric["qps"][service_name] = service['values']

        except Exception as e:
            print(e)

        # 内存
        mem_expr = 'sum by (pod) (container_memory_working_set_bytes{job="kubelet", image!="",container_name!="POD",namespace="%s"})' % (namespace,)
        # print(mem_expr)
        params = {
            'query': mem_expr,
            'start': int(time.time()) - 300,
            'end': int(time.time()),
            'step': "1m",  # 运行小于1分钟的,将不会被采集到
            # 'timeout':"30s"
        }
        print(params)

        try:
            res = requests.get(url=self.query_range_path, params=params)
            metrics = json.loads(res.content.decode('utf8', 'ignore'))
            if metrics['status'] == 'success':
                metrics = metrics['data']['result']
                if metrics:
                    for pod in metrics:
                        pod_name = pod['metric']['pod']
                        if pod_name not in service_metric['memory']:
                            service_metric[pod_name] = {}
                        service_metric['memory'][pod_name] = pod['values']

        except Exception as e:
            print(e)

        # cpu获取
        cpu_expr = "sum by (pod) (rate(container_cpu_usage_seconds_total{namespace='%s',container!='POD'}[1m]))" % (namespace)

        params = {
            'query': cpu_expr,
            'start': int(time.time()) - 300,
            'end': int(time.time()),
            'step': "1m",  # 运行小于1分钟的,将不会被采集到
            # 'timeout':"30s"
        }
        print(params)
        try:

            res = requests.get(url=self.query_range_path, params=params)
            metrics = json.loads(res.content.decode('utf8', 'ignore'))
            if metrics['status'] == 'success':
                metrics = metrics['data']['result']
                if metrics:
                    for pod in metrics:
                        pod_name = pod['metric']['pod']
                        if pod_name not in service_metric['cpu']:
                            service_metric[pod_name] = {}
                        service_metric['cpu'][pod_name] = pod['values']

        except Exception as e:
            print(e)

        gpu_expr = "avg by (pod) (DCGM_FI_DEV_GPU_UTIL{namespace='%s'})" % (namespace)

        params = {
            'query': gpu_expr,
            'start': (datetime.datetime.now() - datetime.timedelta(days=1) - datetime.timedelta(hours=8)).strftime('%Y-%m-%dT%H:%M:%S.000Z'),
            'end': datetime.datetime.now().strftime('%Y-%m-%dT%H:%M:%S.000Z'),
            'step': "1m",  # 运行小于1分钟的,将不会被采集到
            # 'timeout':"30s"
        }
        print(params)
        try:

            res = requests.get(url=self.query_range_path, params=params)
            metrics = json.loads(res.content.decode('utf8', 'ignore'))
            if metrics['status'] == 'success':
                metrics = metrics['data']['result']
                if metrics:
                    # print(metrics)
                    for pod in metrics:
                        pod_name = pod['metric']['pod']
                        if pod_name not in service_metric['gpu']:
                            service_metric['gpu'][pod_name] = {}
                        service_metric['gpu'][pod_name] = pod['values']

        except Exception as e:
            print(e)

        return service_metric



    # 获取当前pod利用率
    # @pysnooper.snoop()
    def get_resource_metric(self):
        max_cpu = 0
        max_mem = 0
        ave_gpu = 0
        pod_metric = {}
        # 这个pod  30分钟内的最大值
        mem_expr = "sum by (pod) (container_memory_working_set_bytes{container!='POD', container!=''})"
        # print(mem_expr)
        params = {
            'query': mem_expr,
            'start': int(time.time()) - 300,
            'end': int(time.time()),
            'step': "1m",  # 运行小于1分钟的,将不会被采集到
            # 'timeout':"30s"
        }
        print(params)

        try:
            res = requests.get(url=self.query_range_path, params=params)
            metrics = json.loads(res.content.decode('utf8', 'ignore'))
            if metrics['status'] == 'success':
                metrics = metrics['data']['result']
                if metrics:
                    for pod in metrics:
                        if pod['metric']:
                            pod_name = pod['metric']['pod']
                            values = max([float(x[1]) for x in pod['values']])
                            if pod_name not in pod_metric:
                                pod_metric[pod_name] = {}
                            pod_metric[pod_name]['memory'] = round(values / 1024 / 1024 / 1024, 2)

        except Exception as e:
            print(e)

        cpu_expr = "sum by (pod) (rate(container_cpu_usage_seconds_total{container!='POD'}[1m]))"

        params = {
            'query': cpu_expr,
            'start': int(time.time()) - 300,
            'end': int(time.time()),
            'step': "1m",  # 运行小于1分钟的,将不会被采集到
            # 'timeout':"30s"
        }
        print(params)
        try:

            res = requests.get(url=self.query_range_path, params=params)
            metrics = json.loads(res.content.decode('utf8', 'ignore'))
            if metrics['status'] == 'success':
                metrics = metrics['data']['result']
                if metrics:
                    for pod in metrics:
                        if pod['metric']:
                            pod_name = pod['metric']['pod']
                            values = [float(x[1]) for x in pod['values']]
                            # values = round(sum(values) / len(values), 2)
                            values = round(max(values), 2)
                            if pod_name not in pod_metric:
                                pod_metric[pod_name] = {}
                            pod_metric[pod_name]['cpu'] = values

        except Exception as e:
            print(e)

        gpu_expr = "avg by (pod) (DCGM_FI_DEV_GPU_UTIL)"

        params = {
            'query': gpu_expr,
            'start': int(time.time()) - 300,
            'end': int(time.time()),
            'step': "1m",  # 运行小于1分钟的,将不会被采集到
            # 'timeout':"30s"
        }
        print(params)
        try:

            res = requests.get(url=self.query_range_path, params=params)
            metrics = json.loads(res.content.decode('utf8', 'ignore'))
            if metrics['status'] == 'success':
                metrics = metrics['data']['result']
                if metrics:
                    # print(metrics)
                    for pod in metrics:
                        if pod['metric']:
                            pod_name = pod['metric']['pod']
                            values = [float(x[1]) for x in pod['values']]
                            # values = round(sum(values)/len(values),2)
                            values = round(max(values), 2)
                            if pod_name not in pod_metric:
                                pod_metric[pod_name] = {}
                            pod_metric[pod_name]['gpu'] = values / 100

        except Exception as e:
            print(e)

        return pod_metric

    # @pysnooper.snoop()
    def get_namespace_resource_metric(self, namespace):
        max_cpu = 0
        max_mem = 0
        ave_gpu = 0
        pod_metric = {}
        # 这个pod  30分钟内的最大值
        mem_expr = "sum by (pod) (container_memory_working_set_bytes{namespace='%s',container!='POD', container!=''})" % (namespace,)
        # print(mem_expr)
        params = {
            'query': mem_expr,
            'start': int(time.time()) - 60*60*24,
            'end': int(time.time()),
            'step': "1m",  # 运行小于1分钟的,将不会被采集到
            # 'timeout':"30s"
        }
        print(params)

        try:
            res = requests.get(url=self.query_range_path, params=params)
            metrics = json.loads(res.content.decode('utf8', 'ignore'))
            if metrics['status'] == 'success':
                metrics = metrics['data']['result']
                if metrics:
                    for pod in metrics:
                        pod_name = pod['metric']['pod']
                        values = max([float(x[1]) for x in pod['values']])
                        if pod_name not in pod_metric:
                            pod_metric[pod_name] = {}
                        pod_metric[pod_name]['memory'] = round(values / 1024 / 1024 / 1024, 2)

        except Exception as e:
            print(e)

        cpu_expr = "sum by (pod) (rate(container_cpu_usage_seconds_total{namespace='%s',container!='POD'}[1m]))" % (namespace)

        params = {
            'query': cpu_expr,
            'start': int(time.time()) - 60*60*24,
            'end': int(time.time()),
            'step': "1m",  # 运行小于1分钟的,将不会被采集到
            # 'timeout':"30s"
        }
        print(params)
        try:

            res = requests.get(url=self.query_range_path, params=params)
            metrics = json.loads(res.content.decode('utf8', 'ignore'))
            if metrics['status'] == 'success':
                metrics = metrics['data']['result']
                if metrics:
                    for pod in metrics:
                        pod_name = pod['metric']['pod']
                        values = [float(x[1]) for x in pod['values']]
                        # values = round(sum(values) / len(values), 2)
                        values = round(max(values), 2)
                        if pod_name not in pod_metric:
                            pod_metric[pod_name] = {}
                        pod_metric[pod_name]['cpu'] = values

        except Exception as e:
            print(e)

        gpu_expr = "avg by (pod) (DCGM_FI_DEV_GPU_UTIL{namespace='%s'})" % (namespace)

        params = {
            'query': gpu_expr,
            'start': int(time.time()) - 60*60*24,
            'end': int(time.time()),
            'step': "1m",  # 运行小于1分钟的,将不会被采集到
            # 'timeout':"30s"
        }
        print(params)
        try:

            res = requests.get(url=self.query_range_path, params=params)
            metrics = json.loads(res.content.decode('utf8', 'ignore'))
            if metrics['status'] == 'success':
                metrics = metrics['data']['result']
                if metrics:
                    # print(metrics)
                    for pod in metrics:
                        pod_name = pod['metric']['pod']
                        values = [float(x[1]) for x in pod['values']]
                        # values = round(sum(values)/len(values),2)
                        values = round(max(values), 2)
                        if pod_name not in pod_metric:
                            pod_metric[pod_name] = {}
                        pod_metric[pod_name]['gpu'] = values / 100

        except Exception as e:
            print(e)

        return pod_metric

        # @pysnooper.snoop()

    def get_pod_resource_metric(self, pod_name, namespace):
        max_cpu = 0
        max_mem = 0
        ave_gpu = 0

        # 这个pod  30分钟内的最大值
        mem_expr = "sum by (pod) (container_memory_working_set_bytes{namespace='%s', pod=~'%s.*',container!='POD', container!=''})"%(namespace,pod_name)
        # print(mem_expr)
        params = {
            'query': mem_expr,
            'start': int(time.time()) - 60*60*24,
            'end': int(time.time()),
            'step': "1m",  # 运行小于1分钟的,将不会被采集到
            # 'timeout':"30s"
        }
        print(params)

        try:
            res = requests.get(url=self.query_range_path, params=params)
            metrics = json.loads(res.content.decode('utf8', 'ignore'))
            if metrics['status'] == 'success':
                metrics = metrics['data']['result']
                if metrics:
                    metrics = metrics[0]['values']
                    for metric in metrics:
                        if int(metric[1]) > max_mem:
                            max_mem = int(metric[1]) / 1024 / 1024 / 1024

        except Exception as e:
            print(e)

        cpu_expr = "sum by (pod) (rate(container_cpu_usage_seconds_total{namespace='%s',pod=~'%s.*',container!='POD'}[1m]))" % (namespace, pod_name)

        params = {
            'query': cpu_expr,
            'start': int(time.time()) - 60*60*24,
            'end': int(time.time()),
            'step': "1m",  # 运行小于1分钟的,将不会被采集到
            # 'timeout':"30s"
        }
        print(params)
        try:

            res = requests.get(url=self.query_range_path, params=params)
            metrics = json.loads(res.content.decode('utf8', 'ignore'))
            if metrics['status'] == 'success':
                metrics = metrics['data']['result']
                if metrics:
                    metrics = metrics[0]['values']
                    for metric in metrics:
                        if float(metric[1]) > max_cpu:
                            max_cpu = float(metric[1])
        except Exception as e:
            print(e)

        gpu_expr = "avg by (pod) (DCGM_FI_DEV_GPU_UTIL{namespace='%s',pod=~'%s.*'})" % (namespace, pod_name)

        params = {
            'query': gpu_expr,
            'start': int(time.time()) - 60*60*24,
            'end': int(time.time()),
            'step': "1m",  # 运行小于1分钟的,将不会被采集到
            # 'timeout':"30s"
        }
        print(params)
        try:
            res = requests.get(url=self.query_range_path, params=params)
            metrics = json.loads(res.content.decode('utf8', 'ignore'))
            if metrics['status'] == 'success':
                metrics = metrics['data']['result']
                if metrics:
                    metrics = metrics[0]['values']
                    all_util = [float(metric[1]) for metric in metrics]
                    ave_gpu = sum(all_util) / len(all_util) / 100
        except Exception as e:
            print(e)

        return {"cpu": round(max_cpu, 2), "memory": round(max_mem, 2), 'gpu': round(ave_gpu, 2)}

    # todo 获取机器的负载补充完整
    # @pysnooper.snoop()
    def get_machine_metric(self):
        # 这个pod  30分钟内的最大值
        metrics = {
            "pod_num": "sum(kubelet_running_pod_count)by (node)",
            "request_memory": "",
            "request_cpu": "",
            "request_gpu": "",
            "used_memory": "",
            "used_cpu": "",
            "used_gpu": "",
        }
        back = {}
        for metric_name in metrics:
            # print(mem_expr)
            params = {
                'query': metrics[metric_name],
                'timeout': "30s"
            }
            print(params)
            back[metric_name] = {}

            try:
                res = requests.get(url=self.query_path, params=params)
                metrics = json.loads(res.content.decode('utf8', 'ignore'))
                if metrics['status'] == 'success':
                    metrics = metrics['data']['result']
                    if metrics:
                        for metric in metrics:
                            node = metric['metric']['node']
                            if ':' in node:
                                node = node[:node.index(':')]
                            value = metric['value'][1]
                            back[metric_name][node] = int(value)


            except Exception as e:
                print(e)

        return back

Prometheus 查询语法使用一种类似于函数式编程的表达方式,允许用户从时间序列数据库中提取和聚合数据。你提供的查询语句 cpu_expr 是一个典型的 Prometheus 查询,下面是对其各个部分的详细讲解:

  1. 函数 sum:是一个聚合函数,用于对一组时间序列进行求和。它可以用于计算所有匹配指标的总和。

  2. by (pod)这是一个分组操作,表示将结果按 pod 标签进行分组。这样,查询结果将显示每个 pod 的 CPU 使用量总和。

  3. rate(container_cpu_usage_seconds_total{...}[1m]):

    rate 是一个用于计算时间序列速率的函数。在这里,它计算 container_cpu_usage_seconds_total 指标在过去 1 分钟内的变化率。container_cpu_usage_seconds_total 是一个计数器类型的指标,表示容器 CPU 使用时间的总和。{namespace='%s',container!='POD'} 是一个标签选择器,用于过滤指标。它选择特定命名空间下的所有容器,但排除了名为 POD 的容器。
  • 整体而言,这个查询的目的是计算指定命名空间下,所有非 POD 容器的 CPU 使用率,并按每个 pod 进行分组。通过使用 rate 函数,它可以提供 CPU 使用的实时速率,而不是总使用时间,这样更能反映容器的当前状态。

    def echart(self, filters=None):
        
        prometheus = Prometheus(conf.get('PROMETHEUS', 'prometheus-k8s.monitoring:9090'))
        # 获取 prometheus-k8s 地址
        pod_resource_metric = prometheus.get_resource_metric()
        print('pod_resource_metric', pod_resource_metric)

        all_resource = {
            "mem_all": sum([int(global_cluster_load[cluster_name]['mem_all']) for cluster_name in global_cluster_load]),
            "cpu_all": sum([int(global_cluster_load[cluster_name]['cpu_all']) for cluster_name in global_cluster_load]),
            "gpu_all": sum([int(global_cluster_load[cluster_name]['gpu_all']) for cluster_name in global_cluster_load]),
        }
        all_resource_req = {
            "mem_req": sum([int(global_cluster_load[cluster_name]['mem_req']) for cluster_name in global_cluster_load]),
            "cpu_req": sum([int(global_cluster_load[cluster_name]['cpu_req']) for cluster_name in global_cluster_load]),
            "gpu_req": sum([int(global_cluster_load[cluster_name]['gpu_req']) for cluster_name in global_cluster_load]),
        }
        all_resource_used = {
            "mem_used": sum([pod_resource_metric[x].get('memory', 0) for x in pod_resource_metric]),
            "cpu_used": sum([pod_resource_metric[x].get('cpu', 0) for x in pod_resource_metric]),
            "gpu_used": sum([pod_resource_metric[x].get('gpu', 0) for x in pod_resource_metric]),
        }

        option = {
            "title": [
                {
                    "subtext": __('集群信息'),
                    "MEM_NAME": __('内存请求占有率'),
                    "MEM_VALUE": int(100 * all_resource_req['mem_req'] / (0.001 + all_resource['mem_all'])),
                    "CPU_NAME": __('CPU占用率'),
                    "CPU_VALUE": int(all_resource['cpu_all']),
                    'GPU_NAME': __('GPU总量(卡)'),
                    'GPU_VALUE': int(all_resource['gpu_all']),
                    'MEM_MAX': int(all_resource['mem_all'] * 2),
                    'CPU_MAX': int(all_resource['cpu_all'] * 2),
                    'GPU_MAX': int(all_resource['gpu_all'] * 2)
                },
                {
                    "subtext": __('资源占用率'),
                    "MEM_NAME": __('内存占用率'),
                    "MEM_VALUE": int(100 * all_resource_req['mem_req'] / (0.001 + all_resource['mem_all'])),
                    "CPU_NAME": __('CPU占用率'),
                    "CPU_VALUE": int(100 * all_resource_req['cpu_req'] / (0.001 + all_resource['cpu_all'])),
                    "GPU_NAME": __('GPU占用率'),
                    "GPU_VALUE": int(100 * all_resource_req['gpu_req'] / (0.001 + all_resource['gpu_all']))

                },
                {
                    "subtext": __('资源利用率'),
                    'MEM_NAME': __('内存利用率'),
                    'MEM_VALUE': str(min(100,
                                         int(100 *
                                             all_resource_used[
                                                 'mem_used'] / (
                                                     0.001 +
                                                     all_resource[
                                                         'mem_all'])))),
                    'CPU_NAME': __('CPU利用率'),
                    'CPU_VALUE': str(min(100, int(100 *
                                                  all_resource_used[
                                                      'cpu_used'] / (
                                                          0.001 +
                                                          all_resource[
                                                              'cpu_all'])))),
                    'GPU_NAME': __('GPU利用率'),
                    'GPU_VALUE': str(min(100, int(100 *
                                                  all_resource_used[
                                                      'gpu_used'] / (
                                                          0.001 +
                                                          all_resource[
                                                              'gpu_all']))))
                }
            ]
        }

        return option

附一个用上面代码实现的运维表盘界面

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2223698.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

RHCE的练习(4)

多端口访问多网站 第一步: 关闭防火墙(因为要与外部连接访问) [rootlocalhost ~]# systemctl stop firewalld [rootlocalhost ~]# setenforce 0第二步: 创建新IP地址(用于区分) [rootlocalhost ~]# nmcli…

【南方科技大学】CS315 Computer Security 【Lab6 IoT Security and Wireless Exploitation】

目录 Introduction (Part 1: OS Security for IoT )Software RequirementsStarting the Lab 6 Virtual MachineSetting up the Zephyr Development EnvironmentDownload the Zephyr Source CodeInstalling Requirements and DependenciesSetting the Project’s Environment Va…

PoissonRecon学习笔记

1. Screened Poisson Reconstruction (SPR) 源码:https://github.com/mkazhdan/PoissonRecon However, as noted by several researchers, it suffers from a tendency to over-smooth the data. 泊松重建存在过度平滑的现象。 方法:position and gradi…

为Windows Terminal 配置zsh + Oh-My-Zsh!

参考: 为Windows Terminal 配置zsh Oh-My-Zsh! [非WSL] https://zhuanlan.zhihu.com/p/625583037 Package: zsh - MSYS2 Packages 安装配置 1、安装 Windows Terminal(必须) Method 1: 打开 Microsoft Store,搜索 “Windows Terminal”。点击 “…

Web应用框架-Django应用基础

1. 认识Django Django是一个用Python编写的开源高级Web框架, 旨在快速开发可维护和可扩展的Web应用程序。 使用Django框架的开发步骤: 1.选择合适的版本 2.安装及配置 3.生成项目结构 4.内容开发 5.迭代、上线、维护 Django官网: Djang…

开源表单生成器OpnForm

什么是 OpnForm ? OpnForm 是一个开源的表单构建工具,旨在简化创建自定义表单的过程,特别适合无编码知识的用户。它通过人工智能优化表单创建流程,支持多种用途,如联系人表单、调查表等。OpnForm 提供了一个直观的拖放…

最优化方法-无约束优化算法(最速下降法)matlab实现

一、前言 最速下降法 ,又称为梯度法,是一种无约束求解多元函数极小值的方法。最速下降法的起源可以追溯到19世纪,最早由数学家Cauchy在1847年提出。随着计算机技术的发展,最速下降法在20世纪50年代逐渐应用于各种优化问题&#x…

BD数字化装备车场:RFID技术的突破之道

传统的车库管理流程主要依赖手工方式,这无疑降低了作业效率,尤其在任务高峰期或紧急情况下,车库进出口的交通堵塞问题尤为突出。随着2023年的到来,我国相继发布了《交通强国建设纲要》与《数字中国建设整体布局规划》等关键政策文…

Uni-App-01

HBuilder安装卸载 安装 下载HBuilder最新版 解压到安装目录,路径中不要有中文和空格 在桌面上增加快捷方式 卸载 执行reset.bat 删除HBuilder文件夹(如果提示文件被占用,杀死相关进程再删除) 夜神模拟器安装 安装 下…

Flutter项目打包ios, Xcode 发布报错 Module‘flutter barcode_scanner‘not found

报错图片 背景 flutter 开发的 apple app 需要发布新版本,但是最后一哆嗦碰到个报错,这个小问题卡住了我一天,之间的埪就不说了,直接说我是怎么解决的,满满干货 思路 这个报错 涉及到 flutter_barcode_scanner; 所…

智能园艺:Spring Boot植物健康系统

1系统概述 1.1 研究背景 随着计算机技术的发展以及计算机网络的逐渐普及,互联网成为人们查找信息的重要场所,二十一世纪是信息的时代,所以信息的管理显得特别重要。因此,使用计算机来管理植物健康系统的相关信息成为必然。开发合适…

《面向对象系统分析与设计》三级项目

文章目录 一、项目总体要求<设计模式应用>第一次文档要求第二次文档要求 二、示例第一次文档 - 设计原则应用1、题目描述2、设计:(1&#xff09;优化理由陈述(2&#xff09;类图(3)实现代码 第二次文档 - 设计模式应用1、题目描述2、设计:(1) 优化理由陈述(2&#xff09;…

PostGis空间(下):空间连接与空间索引

目录 1、简介2、空间连接3、空间索引3.1 索引操作3.2 空间索引的工作原理3.2.1 R-Tree 3.3 空间索引函数3.4 仅索引查询3.5 ANALYZE3.6 VACUUMing3.7 函数列表 PS 1024到啦&#xff01;&#xff01;&#xff01; 先祝各位程序员或者想成为程序员正在奋斗中的伙伴1024程序员节快…

pdf免费压缩软件 pdf文件压缩免费软件 软件工具方法

pdf文件压缩免费软件&#xff1f;对于提升日常工作效率至关重要。在繁忙的工作流程中&#xff0c;寻找一种既高效又合适的压缩策略显得尤为重要。那么&#xff0c;我们该如何优化工作流程呢&#xff1f;在职场中&#xff0c;良好的开端是制定一套清晰的工作方案。只有明确了目标…

Konva 组,层级

代码&#xff1a; <template><div class"rect"><div class"header"> <!-- <el-button type"primary" click"show">展示</el-button>--> <!-- <el-button type"success&quo…

算法设计与分析——动态规划

1.动态规划基础 1.1动态规划的基本思想 动态规划建立在最优原则的基础上&#xff0c;在每一步决策上列出可能的局部解&#xff0c;按某些条件舍弃不能得到最优解的局部解&#xff0c;通过逐层筛选减少计算量。每一步都经过筛选&#xff0c;以每一步的最优性来保证全局的最优性…

UniHttp 框架,请求http接口

项目案例下载地址: https://download.csdn.net/download/jinhuding/89902024 1.快速开始 2.1引入依赖 <dependency><groupId>io.github.burukeyou</groupId><artifactId>uniapi-http

react18中使用redux管理公共数据仓库实现数据immutable更新

Immutable.js出自Facebook&#xff0c;是最流行的不可变数据结构的实现之一。它实现了完全的持久化数据结构&#xff0c;使用结构共享。所有的更新操作都会返回新的值&#xff0c;但是在内部结构是共享的&#xff0c;来减少内存占用。Immutablejs官网 在上一篇介绍redux的文章&…

Docker 部署 JDK11 图文并茂简单易懂

部署 JDK11 ( Docker ) [Step 1] : 下载JDK11 - JDK 11 | Oracle 甲骨文官网 [Step 2] : jdk11上传服务器/root/jdk11 可自行创建文件夹 进入目录 /root/jdk11 解压文件 tar -zxvf jdk-11.0.22_linux-x64_bin.tar.gz解压后 进入 /root/jdk11/jdk-11.0.22 创建 jre 文件 ./bi…

基于RK3588/算能BM1684 AI盒子:综合视频智能AI分析系统建设方案(三)安全帽、睡岗检测、电瓶车、吸烟场景

安全帽反光衣检测算法 功能说明 安全帽反光衣检测是指在监控场景中预先设定监测区域&#xff0c;在区域内人员没有穿戴安全帽反光衣的现象&#xff0c;及时触发告警。检测目标在1080p图像中的分辨率大小不小于30*30像素。 推荐场景 场景要求&#xff1a;可室内外使用&#x…