[英]Prometheus monitoring Kubernetes Container Memory usage and report if container using more than 90%
Looking for example how to monitor Container Memory Usage with Prometheus.寻找如何使用 Prometheus 监控容器内存使用情况的示例。
It reports all the containers ok if we using this query:如果我们使用这个查询,它会报告所有容器正常:
(container_memory_usage_bytes / container_spec_memory_limit_bytes) * 100 > 90
However works ok if container does not have a memory limit defined.但是,如果容器没有定义内存限制,则可以正常工作。 The the divisor is 0, and the results are +Inf, meaning that the alert triggers incorrectly since +Inf matches > 90.除数为 0,结果为 +Inf,这意味着警报触发错误,因为 +Inf 匹配 > 90。
Any suggestions how to properly use Container Memory Usage monitoring?关于如何正确使用容器内存使用监控的任何建议?
I asked the same question from a different perspective just a few days earlier here .我问从不同的角度更早短短几天同样的问题在这里。 So far I have not found an answer.到目前为止,我还没有找到答案。 I have settled with adding another label has_memory_limit
that I use to only alert on containers that have a limit defined.我已经解决了添加另一个标签has_memory_limit
,我用它来仅对定义了限制的容器发出警报。
Okay, I have figured it out:好的,我已经想通了:
((container_memory_usage_bytes / container_spec_memory_limit_bytes) != +Inf) * 100 > 52
Since positive infinity, negative infinity and NaN are numbers in Prometheus , you can simply filter them out with != +Inf
.由于正无穷大、负无穷大和 NaN 是Prometheus中的数字,您可以简单地使用!= +Inf
它们过滤掉。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.