Prometheus 监控 Kubernetes 容器内存使用情况并在容器使用超过 90% 时报告

Prometheus monitoring Kubernetes Container Memory usage and report if container using more than 90%

正在寻找如何使用 Prometheus 监控容器内存使用情况的示例。

如果我们使用此查询,它会报告所有容器都正常:

(container_memory_usage_bytes / container_spec_memory_limit_bytes) * 100 > 90

但是,如果容器没有定义内存限制,则工作正常。除数为 0,结果为 +Inf,这意味着警报触发不正确,因为 +Inf 匹配 > 90。

关于如何正确使用容器内存使用监控的任何建议?

几天前我从不同的角度问过同样的问题here。到目前为止我还没有找到答案。我已经解决了添加另一个标签 has_memory_limit 的问题,我只用它来提醒已定义限制的容器。


好的,我想通了:

((container_memory_usage_bytes / container_spec_memory_limit_bytes) != +Inf)  * 100 > 52

由于正无穷大、负无穷大和 NaN 是 Prometheus 中的数字,您可以简单地用 != +Inf.

过滤掉它们