[英]How to query container memory limit in Prometheus
I am using Prometheus tool for monitoring my Kube.netes cluster.我正在使用 Prometheus 工具来监控我的 Kube.netes 集群。
I have set a resource limit(memory limit) in my deployments and need to configure a panel for showing the total memory available.我在我的部署中设置了资源限制(内存限制),需要配置一个面板来显示可用的总数 memory。 Please let me know the query needed to run in Prometheus for getting the total memory limit available for my deployment.
请让我知道在 Prometheus 中运行所需的查询以获得可用于我的部署的总 memory 限制。
It is possible using metrics kube_pod_container_resource_limits_memory_bytes (provided by kube-state-metrics ) and container_memory_usage_bytes (provided by kubelet/cAdvisor) 可以使用指标kube_pod_container_resource_limits_memory_bytes(由kube-state-metrics提供 )和container_memory_usage_bytes(由kubelet / cAdvisor提供)
label_replace(
label_replace(
kube_pod_container_resource_limits_memory_bytes{},
"pod_name",
"$1",
"pod",
"(.+)"
),
"container_name",
"$1",
"container",
"(.+)"
)
-
on(pod_name,namespace,container_name)
avg(
container_memory_usage_bytes{pod_name=~".+"}
)
by (pod_name,namespace,container_name)
A little explanation of the query: It is a subtraction of the memory limit and the actual usage. 关于查询的一些解释:这是内存限制和实际使用量的减去。
label_replace
functions are needed to match the label names of both metrics, as they are obtained from different targets. 需要使用
label_replace
函数来匹配两个度量的标签名称,因为它们是从不同的目标获得的。 avg
is used to get the average between pod restarts, as every pod restart creates a new metric. 由于每次pod重新启动都会创建一个新指标,因此
avg
用于获取pod重新启动之间的平均值。 {pod_name=~".+"}
is used to filter metrics from container_memory_usage_bytes
that are not useful for this case {pod_name=~".+"}
用于从container_memory_usage_bytes
中过滤对这种情况无用的指标
The following PromQL query returns per-container free memory starting from Kube.netes v1.16:从 Kube.netes v1.16 开始,以下 PromQL 查询返回每个容器免费 memory:
kube_pod_container_resource_limits{resource="memory"}
- on(namespace, pod, container)
container_memory_usage_bytes
The on()
modifier instructs Prometheus to take into account only the listed labels when finding pairs of time series with identical labels on the left and the right side of -
operator. on()
修饰符指示 Prometheus 在查找-
运算符左侧和右侧具有相同标签的时间序列对时仅考虑列出的标签。 See these docs for details.有关详细信息,请参阅这些文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.