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

Quarkus中使用reactive-pg-client时Postgres数据源指标无法在/q/metrics获取

解决Quarkus反应式PostgreSQL客户端指标不显示的问题

核心原因

Quarkus的quarkus-reactive-pg-client扩展默认不会自动暴露数据库指标,需要手动开启相关配置,同时确保Micrometer的集成配置正确。

具体配置步骤

  1. 开启反应式PG客户端的指标收集
    在application.properties中添加以下配置:

    quarkus.reactive-pg-client.metrics.enabled=true
    

    该配置会启用反应式PostgreSQL客户端的指标收集,涵盖连接池状态、查询耗时、活跃连接数等核心指标。

  2. 验证Micrometer Prometheus注册表配置
    确保Prometheus注册表配置正确,默认情况下quarkus-micrometer-registry-prometheus会自动暴露/q/metrics端点,若有自定义配置,需确认以下配置存在:

    quarkus.micrometer.registry.prometheus.enabled=true
    quarkus.micrometer.export.prometheus.enabled=true
    
  3. 检查依赖完整性
    确认项目依赖中已包含正确的扩展:

    • Maven(pom.xml):
      <dependency>
          <groupId>io.quarkus</groupId>
          <artifactId>quarkus-reactive-pg-client</artifactId>
      </dependency>
      <dependency>
          <groupId>io.quarkus</groupId>
          <artifactId>quarkus-micrometer-registry-prometheus</artifactId>
      </dependency>
      
    • Gradle(build.gradle):
      implementation 'io.quarkus:quarkus-reactive-pg-client'
      implementation 'io.quarkus:quarkus-micrometer-registry-prometheus'
      

可获取的指标示例

开启配置后,访问/q/metrics可看到以下PostgreSQL相关指标:

  • pg_client_connections_active:当前活跃连接数
  • pg_client_connections_idle:当前空闲连接数
  • pg_client_queries_duration_seconds:查询耗时的分布统计(分位数、最大值等)
  • pg_client_queries_total:执行的查询总数

注意事项

  • 版本兼容性:Quarkus 2.9.0.Final的quarkus-reactive-pg-client已原生支持Micrometer指标集成,无需额外补丁。
  • 多数据源场景:若使用命名的反应式PG客户端(配置多个数据源),需为每个客户端单独开启指标:
    quarkus.reactive-pg-client.<client-name>.metrics.enabled=true
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.06 08:50:26