Class PrometheusMetricsManager
java.lang.Object
de.cuioss.benchmarking.common.metrics.PrometheusMetricsManager
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 Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clears all tracked timestamps.voidcollectMetricsForResults(Collection<org.openjdk.jmh.results.RunResult> results, BenchmarkConfiguration config) Collects Prometheus metrics for completed benchmarks.voidcollectMetricsForWrkBenchmark(String benchmarkName, Instant startTime, Instant endTime, String outputDirectory) Collects Prometheus metrics for WRK benchmark results.voidrecordBenchmarkStart(String benchmarkName) Records the start time for a benchmark execution.voidrecordBenchmarkTimestamps(String benchmarkName, Instant startTime, Instant endTime) Records both start and end timestamps for a benchmark.
-
Field Details
-
PROMETHEUS_DIR_NAME
- See Also:
-
PROMETHEUS_URL_PROPERTY
- See Also:
-
PROMETHEUS_URL_DEFAULT
- See Also:
-
METRICS_FILE_SUFFIX
- See Also:
-
-
Constructor Details
-
PrometheusMetricsManager
public PrometheusMetricsManager()Creates a new PrometheusMetricsManager. Prometheus URL is read from system property or defaults to localhost:9090.
-
-
Method Details
-
recordBenchmarkStart
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
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 benchmarkstartTime- the benchmark start timeendTime- 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 resultsconfig- 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 benchmarkstartTime- the benchmark start timeendTime- the benchmark end timeoutputDirectory- the directory to save metrics
-
clear
Clears all tracked timestamps. Useful for testing or when reusing the manager for multiple benchmark runs.
-