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

使用Prometheus编写Pulsar指标查询遇阻:返回非预期指标求解答

Troubleshooting Your Pulsar Subscription Count Query in Prometheus

Hey there, let's break down why you're getting JVM metrics instead of the Pulsar subscription count you're after—this is a common mix-up when starting out with these tools!

First: You're Using the Wrong Endpoint for PromQL Queries

The biggest issue here is that you're hitting the /metrics endpoint, which is where services (like the Pulsar broker) expose raw metrics data, not where you run Prometheus queries. Prometheus has a dedicated API endpoint for executing PromQL queries:

Instead of this:

GET http://localhost:8000/metrics?query=pulsar_subscriptions_count{cluster="pulsar-cluster",namespace="default",topic="measurements-combined"}

You need to use Prometheus's query API (default port for Prometheus is 9090):

GET http://localhost:9090/api/v1/query?query=pulsar_subscriptions_count{cluster="pulsar-cluster",namespace="default",topic="measurements-combined"}

Next: Double-Check Prometheus is Scraping Pulsar's Metrics

Even with the right endpoint, you won't get results unless Prometheus is actually collecting Pulsar's metrics. Here's how to confirm:

  • Open your Prometheus config file (prometheus.yml) and make sure you have a scrape job for Pulsar. It should look something like this (Pulsar brokers default to exposing metrics on port 8080):
    scrape_configs:
      - job_name: 'pulsar-broker'
        static_configs:
          - targets: ['localhost:8080']
    
  • Restart Prometheus to apply the config.
  • Head to the Prometheus UI at http://localhost:9090/targets and verify the pulsar-broker target shows as "UP".

Then: Verify the Metric and Labels Exist

Before running your filtered query, confirm the metric itself is available:

  • Go to the Prometheus UI's Graph page (http://localhost:9090/graph).
  • Run a basic query: pulsar_subscriptions_count (no labels). If you see results, that means Prometheus is pulling the metric.
  • Check the labels attached to those results—make sure your cluster, namespace, and topic names match exactly (they're case-sensitive!). For example, if the cluster label is actually local-cluster instead of pulsar-cluster, your filtered query won't return anything.

One Last Check: Confirm Pulsar's Metrics Are Enabled

Pulsar enables metrics by default, but if you've modified broker configs, double-check that metricsEnabled is set to true in your Pulsar broker config file. You can also directly hit Pulsar's metrics endpoint (e.g., http://localhost:8080/metrics) and search for pulsar_subscriptions_count to ensure it's being exposed.

Give those steps a try, and you should start seeing the subscription count you're looking for!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.06 08:19:07