【问题标题】:Prometheus queries to get CPU and Memory usage in kubernetes podsPrometheus 查询以获取 kubernetes pod 中的 CPU 和内存使用情况
【发布时间】:2019-08-04 05:37:33
【问题描述】:

我需要使用 prometheus 查询来获取 kubernetes pod 中的 CPU 和内存使用情况。有人可以帮忙吗?

【问题讨论】:

  • 请提供更多关于您当前情况的信息。 Prometheus 是否已启动并正在运行,但您不知道如何查询指标?您是否无法让 Prometheus 在您的集群中运行?
  • 是的。它已启动并正在运行我希望收到有关 pod 的 CPU 和内存使用情况的警报。为此,我需要进行普罗米修斯查询。请问你用的是什么?
  • 我想要这样的东西 "sum(container_memory_usage_bytes{namespace="$namespace", pod_name="$pod", container_name!="POD"}) by (container_name)" 因为有此查询中的变量我无法发送警报。
  • 请使用您尝试过的任何查询来编辑您的问题。

标签: kubernetes grafana prometheus promql


【解决方案1】:

您是否使用 prometheus-operator 从 kubernetes 收集数据? 如果是,你可以使用这样的东西: 总和(container_memory_usage_bytes) 总和(container_cpu_usage_seconds_total) 举个例子。

【讨论】:

  • 我想要这样的东西 "sum(container_memory_usage_bytes{namespace="$namespace", pod_name="$pod", container_name!="POD"}) by (container_name)" 因为有此查询中的变量我无法发送警报。
【解决方案2】:

CPU 百分比

avg((sum (rate (container_cpu_usage_seconds_total {container_name!="" ,pod="<Pod name>" } [5m])) by (namespace , pod, container ) / on (container , pod , namespace) ((kube_pod_container_resource_limits_cpu_cores >0)*300))*100)

内存百分比

avg((avg (container_memory_working_set_bytes{pod="<pod name>"}) by (container_name , pod ))/ on (container_name , pod)(avg (container_spec_memory_limit_bytes>0 ) by (container_name, pod))*100)

您可以在查询中使用上面带有 pod 名称的 promql。

【讨论】:

  • 你为什么要乘以 300
猜你喜欢
  • 2021-05-09
  • 2019-06-29
  • 2021-07-02
  • 1970-01-01
  • 2021-06-29
  • 1970-01-01
  • 2020-06-25
  • 2021-01-05
  • 1970-01-01
相关资源
最近更新 更多