You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

如何在单个PromQL查询中同时获取两个Prometheus指标值?

How to Fetch Two Prometheus Metrics in a Single Query with Shared Labels

Got it, let's work through this problem to get your desired table-style result.

The core trick here is using PromQL's join operator, which lets you combine two metric series based on the shared labels you care about. Here's how to do it step by step:

Basic Query to Combine Metrics

join on (Label1, Label2) (
  http_request_duration_seconds_bucket,
  http_request_duration_seconds_count
)

This query matches up series from both metrics where the values of Label1 and Label2 are identical. The result will include:

  • Your shared labels Label1 and Label2
  • The value from http_request_duration_seconds_bucket
  • The value from http_request_duration_seconds_count

Rename Metrics for Clearer Output

If you want the result columns to explicitly show as metric1 and metric2 instead of the original metric names, use the alias() function to rename them:

join on (Label1, Label2) (
  alias(http_request_duration_seconds_bucket, "metric1"),
  alias(http_request_duration_seconds_count, "metric2")
)

Aggregate First (For Rolled-Up Results)

If your metrics have extra labels you don't need, or if you want to roll up values per Label1/Label2 pair, aggregate each metric before joining:

join on (Label1, Label2) (
  sum(http_request_duration_seconds_bucket) by (Label1, Label2),
  sum(http_request_duration_seconds_count) by (Label1, Label2)
)

This ensures each unique Label1 + Label2 combination has a single row in the result, which fits perfectly with your desired table format.

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

火山引擎 最新活动