[英]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
sum(rate(container_cpu_usage_seconds_total{pod=~"MY_POD"}[5m]))
查询 A: sum(rate(container_cpu_usage_seconds_total{pod=~"MY_POD"}[5m]))
sum(kube_pod_container_resource_requests{pod=~"MY_POD"})
查询 B: sum(kube_pod_container_resource_requests{pod=~"MY_POD"})
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.