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

如何获取Prometheus图表中最大值首次出现的时间戳?

解决Prometheus获取指标最大值首次出现时间戳的问题

你的查询语句之所以返回最晚的时间戳,是因为max(jmeter_count_total{label="GET - Company Updates - ua_users_company-updates"})会先计算整个时间范围内的最大值,得到的是一个仅包含该最大值的单样本(对应这个值最后出现的时间点),再套timestamp()和min()自然拿不到最早的时间点。

要获取最大值首次出现的时间戳,得先筛选出所有等于最大值的样本,再取这些样本里最小的时间戳,试试这两种写法:

方法一:用匹配运算符关联最大值

min_over_time(timestamp(jmeter_count_total{label="GET - Company Updates - ua_users_company-updates"} == on() group_left() max(jmeter_count_total{label="GET - Company Updates - ua_users_company-updates"}))[1d:])
  • 先通过max(...)算出指标的全局最大值
  • 用== on() group_left()匹配出所有值等于最大值的样本
  • 最后用min_over_time()提取这些样本时间戳的最小值,也就是首次出现的时间

方法二:用标量匹配

min(timestamp(jmeter_count_total{label="GET - Company Updates - ua_users_company-updates"} == scalar(max(jmeter_count_total{label="GET - Company Updates - ua_users_company-updates"}))))
  • scalar()把最大值转为标量值
  • 匹配所有等于该标量的样本后,取这些样本时间戳的最小值

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.21 14:57:22