Class MetricsJsonExporter

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

public class MetricsJsonExporter extends Object
Exports metrics data to JSON files in a target directory. Handles JSON serialization, file writing, and metrics aggregation.
  • Field Details

  • Constructor Details

    • MetricsJsonExporter

      public MetricsJsonExporter(Path targetDirectory)
      Creates a new metrics JSON exporter.
      Parameters:
      targetDirectory - Directory where JSON files will be written
  • Method Details

    • exportToFile

      public void exportToFile(String fileName, Map<String,Object> metricsData) throws IOException
      Exports metrics data to a JSON file.
      Parameters:
      fileName - The name of the JSON file
      metricsData - The metrics data to export
      Throws:
      IOException - if writing fails
    • exportJwtValidationMetrics

      public void exportJwtValidationMetrics(String benchmarkMethodName, Instant timestamp, Map<String,Double> allMetrics) throws IOException
      Exports JWT validation metrics for a specific benchmark method.
      Parameters:
      benchmarkMethodName - The name of the benchmark method
      timestamp - The timestamp when the benchmark was executed
      allMetrics - All metrics data
      Throws:
      IOException - if export fails
    • exportResourceMetrics

      public void exportResourceMetrics(Instant timestamp, Map<String,Double> allMetrics) throws IOException
      Exports resource metrics (CPU, memory) for system monitoring.
      Parameters:
      timestamp - The timestamp when metrics were collected
      allMetrics - All metrics data
      Throws:
      IOException - if export fails
    • updateAggregatedMetrics

      public void updateAggregatedMetrics(String fileName, String benchmarkName, Map<String,Object> benchmarkData) throws IOException
      Updates an aggregated metrics file with new benchmark data. For quarkus-metrics.json files, applies special transformation to create the new structure.
      Parameters:
      fileName - The name of the aggregated metrics file
      benchmarkName - The name of the benchmark
      benchmarkData - The benchmark data to add/update
      Throws:
      IOException - if writing fails
    • readExistingMetrics

      Reads existing metrics from a JSON file.
      Parameters:
      fileName - The name of the JSON file
      Returns:
      The parsed metrics map, or empty map if file doesn't exist or is empty