You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用Prometheus查询指定Pod指定时间段的内存最大/最小/平均值

PromQL查询指定Pod 6小时内存极值与平均值方案

对应查询语句

你原有的按容器维度聚合的基础查询,配合Prometheus的范围聚合函数,三个指标的实现语句分别如下:

  • 6小时内存峰值(最大值)
max_over_time(
  sum(container_memory_working_set_bytes{namespace="test", pod="test1", container!="POD", container!=""}) by (container)[6h:]
)
  • 6小时内存最小值
min_over_time(
  sum(container_memory_working_set_bytes{namespace="test", pod="test1", container!="POD", container!=""}) by (container)[6h:]
)
  • 6小时内存平均值
avg_over_time(
  sum(container_memory_working_set_bytes{namespace="test", pod="test1", container!="POD", container!=""}) by (container)[6h:]
)

补充说明

  • 语句中[6h:]为范围向量选择器,代表取过去6小时内的所有采样数据,冒号默认适配Prometheus的全局采样步长,无需额外配置
  • 默认返回结果单位为字节,如需转换为GB等可读性更高的单位,可在整条语句末尾追加 / 1024 / 1024 / 1024 做单位转换
  • 如需单条查询同时返回三个指标用于报表导出,可通过or运算符拼接三个查询:
max_over_time(sum(container_memory_working_set_bytes{namespace="test", pod="test1", container!="POD", container!=""}) by (container)[6h:])
or
min_over_time(sum(container_memory_working_set_bytes{namespace="test", pod="test1", container!="POD", container!=""}) by (container)[6h:])
or
avg_over_time(sum(container_memory_working_set_bytes{namespace="test", pod="test1", container!="POD", container!=""}) by (container)[6h:])

内容的提问来源于stack exchange,提问作者pythonhmmm

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.16 02:36:04