Class ObservabilityMetricsExporter

java.lang.Object
cloud.opencode.base.pool.metrics.ObservabilityMetricsExporter

public final class ObservabilityMetricsExporter extends Object
Observability Metrics Exporter with Optional Observability Module Delegation 支持可选 Observability 模块委托的指标导出器

Exports pool metrics to OpenMetrics when the Observability module is available. Registers gauges for pool statistics that are automatically updated.

当 Observability 模块可用时,将池指标导出到 OpenMetrics。 注册自动更新的池统计仪表。

Exported Metrics | 导出的指标:

  • pool.borrow.total - Total borrow count | 总借用次数
  • pool.return.total - Total return count | 总归还次数
  • pool.created.total - Total objects created | 总创建对象数
  • pool.destroyed.total - Total objects destroyed | 总销毁对象数
  • pool.wait.avg.ms - Average wait duration | 平均等待时长
  • pool.borrow.avg.ms - Average borrow duration | 平均借用时长

Features | 主要功能:

  • Optional observability module integration - 可选的 Observability 模块集成
  • Automatic gauge registration for pool statistics - 自动注册池统计仪表
  • Tag-based metric grouping - 基于标签的指标分组
  • Graceful degradation when module unavailable - 模块不可用时优雅降级

Usage Examples | 使用示例:

// Export pool metrics to Observability
ObjectPool<Connection> pool = OpenPool.builder(...).build();
ObservabilityMetricsExporter.export("db-pool", pool.getMetrics());

Security | 安全性:

  • Thread-safe: Yes (utility class with static methods) - 线程安全: 是(静态方法的工具类)
  • Null-safe: Yes (null metrics ignored) - 空值安全: 是(空指标被忽略)
Since:
JDK 25, opencode-base-pool V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • isObservabilityModuleAvailable

      public static boolean isObservabilityModuleAvailable()
      Checks if the Observability module is available. 检查 Observability 模块是否可用
      Returns:
      true if Observability module is available | 如果 Observability 模块可用返回 true
    • export

      public static void export(String poolName, PoolMetrics metrics)
      Exports pool metrics to Observability. 将池指标导出到 Observability
      Parameters:
      poolName - the pool name for tagging | 用于标记的池名称
      metrics - the pool metrics to export | 要导出的池指标
    • export

      public static void export(String prefix, String poolName, PoolMetrics metrics)
      Exports pool metrics with custom prefix. 使用自定义前缀导出池指标
      Parameters:
      prefix - the metric name prefix | 指标名称前缀
      poolName - the pool name for tagging | 用于标记的池名称
      metrics - the pool metrics to export | 要导出的池指标