Class PrometheusMetricsManager

java.lang.Object
de.cuioss.benchmarking.common.metrics.PrometheusMetricsManager

public class PrometheusMetricsManager extends Object
Centralized manager for Prometheus metrics collection during benchmark execution. This class provides a unified approach to collecting real-time metrics from Prometheus for both JMH and WRK benchmarks.

The manager tracks benchmark execution timestamps and collects metrics at the end of benchmark runs. This ensures consistent metrics collection across different benchmark types.

Features:

  • Thread-safe timestamp tracking for concurrent benchmarks
  • Automatic Prometheus client configuration from system properties
  • Unified metrics collection for different benchmark result types
  • Integration with MetricsOrchestrator for actual metrics retrieval
  • Field Details

  • Constructor Details

    • PrometheusMetricsManager

      Creates a new PrometheusMetricsManager. Prometheus URL is read from system property or defaults to localhost:9090.
  • Method Details

    • recordBenchmarkStart

      public void recordBenchmarkStart(String benchmarkName)
      Records the start time for a benchmark execution. This should be called just before benchmark execution begins.
      Parameters:
      benchmarkName - the name of the benchmark
    • recordBenchmarkTimestamps

      public void recordBenchmarkTimestamps(String benchmarkName, Instant startTime, Instant endTime)
      Records both start and end timestamps for a benchmark. Used when timestamps are provided externally (e.g., from WRK output).
      Parameters:
      benchmarkName - the name of the benchmark
      startTime - the benchmark start time
      endTime - the benchmark end time
    • collectMetricsForResults

      public void collectMetricsForResults(Collection<org.openjdk.jmh.results.RunResult> results, BenchmarkConfiguration config)
      Collects Prometheus metrics for completed benchmarks. This should be called after all benchmarks have completed execution.
      Parameters:
      results - the benchmark results
      config - the benchmark configuration
    • collectMetricsForWrkBenchmark

      public void collectMetricsForWrkBenchmark(String benchmarkName, Instant startTime, Instant endTime, String outputDirectory)
      Collects Prometheus metrics for WRK benchmark results. This method handles the specific case of WRK benchmarks where timestamps are extracted from the output files.
      Parameters:
      benchmarkName - the name of the benchmark
      startTime - the benchmark start time
      endTime - the benchmark end time
      outputDirectory - the directory to save metrics
    • clear

      public void clear()
      Clears all tracked timestamps. Useful for testing or when reusing the manager for multiple benchmark runs.