Class PeriodicMetricReader

java.lang.Object
io.opentelemetry.sdk.metrics.export.PeriodicMetricReader
All Implemented Interfaces:
MetricReader

public class PeriodicMetricReader extends Object implements MetricReader
Wraps a MetricExporter and automatically reads and exports the metrics every export interval. Metrics may also be dropped when it becomes time to export again, and there is an export in progress.
  • Method Details

    • create

      public static MetricReaderFactory create(MetricExporter exporter)
      Builds a factory that will register and start a PeriodicMetricReader.

      This will export once every 5 minutes.

      This will spin up a new daemon thread to schedule the export on.

      Parameters:
      exporter - The exporter receiving metrics.
    • create

      public static MetricReaderFactory create(MetricExporter exporter, Duration duration)
      Builds a factory that will register and start a PeriodicMetricReader.

      This will spin up a new daemon thread to schedule the export on.

      Parameters:
      exporter - The exporter receiving metrics.
      duration - The duration (interval) between metric export calls.
    • create

      public static MetricReaderFactory create(MetricExporter exporter, Duration duration, ScheduledExecutorService scheduler)
      Builds a factory that will register and start a PeriodicMetricReader.
      Parameters:
      exporter - The exporter receiving metrics.
      duration - The duration (interval) between metric export calls.
      scheduler - The service to schedule export work.
    • flush

      public io.opentelemetry.sdk.common.CompletableResultCode flush()
      Description copied from interface: MetricReader
      Flushes metrics read by this reader.

      In all scenarios, the associated MetricProducer should have its MetricProducer.collectAllMetrics() method called.

      For push endpoints, this should collect and report metrics as normal.

      Specified by:
      flush in interface MetricReader
      Returns:
      the result of the shutdown.
    • shutdown

      public io.opentelemetry.sdk.common.CompletableResultCode shutdown()
      Description copied from interface: MetricReader
      Shuts down the metric reader.

      For pull endpoints, like prometheus, this should shut down the metric hosting endpoint or server doing such a job.

      For push endpoints, this should shut down any scheduler threads.

      Specified by:
      shutdown in interface MetricReader
      Returns:
      the result of the shutdown.