简体   繁体   English

可视化 K8S CPU 资源 Prometheus 和 Grafana

[英]Visualizing K8S CPU resources Prometheus and Grafana

I'm new with monitoring tools like Prometheus and Grafana and I would like to create dashboard which represents current requests and limits resources and usage for a pod.我是 Prometheus 和 Grafana 等监控工具的新手,我想创建代表当前requests and limits resources和使用的仪表板。 In addition, this pod has 2 containers inside.此外,这个 pod 里面有 2 个容器。

My resources for first container looks like:我的第一个容器的资源如下所示:

 resources:
    requests:
      cpu: "3800m"
      memory: "9500Mi"
    limits:
      cpu: "6500m"
      memory: "9500Mi"

and for second container:对于第二个容器:

resources:
   limits:
     cpu: 100m
     memory: 100Mi
   requests:
     cpu: 50m
     memory: 50Mi

When executing this query in Prometheus:在 Prometheus 中执行此查询时:

rate(container_cpu_usage_seconds_total{pod=~"MY_POD"}[5m]) I get: rate(container_cpu_usage_seconds_total{pod=~"MY_POD"}[5m])我得到: 在此处输入图像描述 And to be honest I dont know how this returned data are valid with resources.老实说,我不知道这些返回的数据对资源是否有效。 On Grafana it looks like this:在 Grafana 上,它看起来像这样: 在此处输入图像描述

In addition I would like to add informations about requests and limits to dashboard, but I don't know how to scale dashboard to show all data.此外,我想向仪表板添加有关requests and limits的信息,但我不知道如何缩放仪表板以显示所有数据。

When I execute this query: kube_pod_container_resource_requests{pod=~"MY_POD"} I get:当我执行此查询时: kube_pod_container_resource_requests{pod=~"MY_POD"}我得到:

在此处输入图像描述

And this looks valid compared to my resources.与我的资源相比,这看起来很有效。 I have proper value for limits too, but I would like to represent all this data (usage, requests, limits) on ona dashboard.我也有适当的限制值,但我想在仪表板上表示所有这些数据(使用情况、请求、限制)。 Could somebody give my any tips how to achieve this?有人可以给我任何提示如何实现这一目标吗?

Simple, just add 2 more queries很简单,只需再添加 2 个查询

if you don't know where to add, below Metrics Browser and Options tab you can find + symbol to add more queries如果您不知道在哪里添加,请在 Metrics Browser 和 Options 选项卡下找到 + 符号以添加更多查询

and container_cpu_usage_seconds_total this metrics is a counter and this will give you the CPU Usage in Cores.container_cpu_usage_seconds_total这个指标是一个计数器,它会给你核心的 CPU 使用率。

kube_pod_container_resource_requests{pod=~"MY_POD"} and kube_pod_container_resource_limits{pod=~"MY_POD"} . kube_pod_container_resource_requests{pod=~"MY_POD"}kube_pod_container_resource_limits{pod=~"MY_POD"} If it's only one Pod means no issues.如果它只有一个 Pod 意味着没有问题。 But if you're having mutliple Pods means try to use Sum但是,如果您有多个 Pod,则意味着尝试使用Sum

  • Query A: sum(rate(container_cpu_usage_seconds_total{pod=~"MY_POD"}[5m]))查询 A: sum(rate(container_cpu_usage_seconds_total{pod=~"MY_POD"}[5m]))
  • Query B: sum(kube_pod_container_resource_requests{pod=~"MY_POD"})查询 B: sum(kube_pod_container_resource_requests{pod=~"MY_POD"})
  • Query C: sum(kube_pod_container_resource_limits{pod=~"MY_POD"})查询 C: sum(kube_pod_container_resource_limits{pod=~"MY_POD"})

This will looks good without too much details, for more details like container wise data just create three more Panel for Requests, Limits and Usage by Containers and add by(container) after the every Query如果没有太多细节,这看起来不错,对于更多细节,如容器明智的数据,只需为容器的请求、限制和使用情况再创建三个面板,并在每个查询之后添加by(container)

Another Approach:另一种方法:

Create Variables for Pod and Container so that you can select the Container which you want to see and add 3 queries in single panel so that the Panel looks more Dynamic and less Noise为 Pod 和容器创建变量,以便您可以 select 您想要查看的容器并在单个面板中添加 3 个查询,以便面板看起来更动态且噪音更少

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为 k8s 集群 pod CPU 使用情况创建 Grafana 警报 - Create Grafana Alert for k8s cluster pods CPU usage 使用 prometheus 计算 k8s 集群 cpu/内存使用情况 - count k8s cluster cpu/memory usage with prometheus k8s prometheus:prometheus 中的哪个指标告诉命名空间的 cpu 和 memory 限制 - k8s prometheus: which metric in prometheus tells namespace's cpu and memory limit 如何获取 K8s 集群中的可用资源(内存、cpu)? - How to get the available resources (memory, cpu) in a K8s cluster? 普罗米修斯(k8s)(指标) - Prometheus in k8s (metrics) 如何配置中央 Prometheus/grafana 来监控/抓取多个 k8s 集群 - How to configure central Prometheus/grafana to monitor/scrape several k8s clusters 如何访问在 Azure 中运行的托管 k8s 上的 ingress-nginx 命名空间中安装的 Prometheus 和 Grafana? - How to access Prometheus and Grafana installed in the ingress-nginx namespace on managed k8s running in Azure? Kubernetes(K8s)-在一段时间内未创建新容器时,从Prometheus / Grafana获取警报 - Kubernetes (K8s) - Get alert from Prometheus/Grafana when a new container is not created with a period of time K8S - 使用 Prometheus 检查证书验证 - K8S - Check certificate validation with Prometheus Prometheus抓取K8s入口端点 - Prometheus to scrape K8s Ingress Endpoints
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM