简体   繁体   English

Prometheus中如何查询容器memory限制

[英]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.

相关问题 Prometheus 查询以获取整个集群的内存限制承诺 - Prometheus query to get memory limit commitment for the entire cluster Kubernetes如何执行容器的内存限制? - How does Kubernetes enforce the memory limit for a container? 缺少Prometheus容器级别的缓冲内存指标 - Prometheus container level buffered memory metric is missing 如何限制普罗米修斯中的目标数量 - how to limit number of targets in prometheus 容器如何使用超过限制的内存? - How does the container use more memory than the limit? Prometheus查询pod memory使用性能的分位数 - Prometheus query quantile of pod memory usage performance k8s prometheus:prometheus 中的哪个指标告诉命名空间的 cpu 和 memory 限制 - k8s prometheus: which metric in prometheus tells namespace's cpu and memory limit Prometheus 监控 Kubernetes 容器内存使用情况并报告容器使用情况是否超过 90% - Prometheus monitoring Kubernetes Container Memory usage and report if container using more than 90% Kubernetes Prometheus:当容器内存使用量大于 kube 节点总内存容量时添加警报 - Kubernetes Prometheus: Add alert when container memory usage is greater than total kube node memory capacity 达到一组内存使用量或CPU限制时如何杀死Docker容器 - How to kill a docker container when it reaches set of memory usage or CPU limit
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM