Class PeriodicMetricReader
- java.lang.Object
-
- io.opentelemetry.sdk.metrics.export.PeriodicMetricReader
-
- All Implemented Interfaces:
AggregationTemporalitySelector,DefaultAggregationSelector,MetricReader,java.io.Closeable,java.lang.AutoCloseable
public final class PeriodicMetricReader extends java.lang.Object implements MetricReader
AMetricReaderwhich wraps aMetricExporterand automatically reads and exports the metrics every export interval.Register with
SdkMeterProviderviaSdkMeterProviderBuilder.registerMetricReader(MetricReader).- Since:
- 1.14.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classPeriodicMetricReader.Scheduled
-
Field Summary
Fields Modifier and Type Field Description private CollectionRegistrationcollectionRegistrationprivate MetricExporterexporterprivate longintervalNanosprivate java.lang.Objectlockprivate static java.util.logging.Loggerloggerprivate PeriodicMetricReader.Scheduledscheduledprivate java.util.concurrent.ScheduledFuture<?>scheduledFutureprivate java.util.concurrent.ScheduledExecutorServicescheduler
-
Constructor Summary
Constructors Constructor Description PeriodicMetricReader(MetricExporter exporter, long intervalNanos, java.util.concurrent.ScheduledExecutorService scheduler)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static PeriodicMetricReaderBuilderbuilder(MetricExporter exporter)Returns a newPeriodicMetricReaderBuilder.static PeriodicMetricReadercreate(MetricExporter exporter)Returns a newPeriodicMetricReaderwhich exports to theexporteronce every minute.CompletableResultCodeforceFlush()Read and export the metrics.AggregationTemporalitygetAggregationTemporality(InstrumentType instrumentType)Return the aggregation temporality for theInstrumentType.AggregationgetDefaultAggregation(InstrumentType instrumentType)Return the default aggregation for theInstrumentType.MemoryModegetMemoryMode()Returns the memory mode used by this reader.voidregister(CollectionRegistration collectionRegistration)Called bySdkMeterProvideron initialization to supply theMetricReaderwithMetricProducers used to collect metrics.CompletableResultCodeshutdown()Shuts down the metric reader.(package private) voidstart()java.lang.StringtoString()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface io.opentelemetry.sdk.metrics.export.DefaultAggregationSelector
with
-
Methods inherited from interface io.opentelemetry.sdk.metrics.export.MetricReader
close
-
-
-
-
Field Detail
-
logger
private static final java.util.logging.Logger logger
-
exporter
private final MetricExporter exporter
-
intervalNanos
private final long intervalNanos
-
scheduler
private final java.util.concurrent.ScheduledExecutorService scheduler
-
scheduled
private final PeriodicMetricReader.Scheduled scheduled
-
lock
private final java.lang.Object lock
-
collectionRegistration
private volatile CollectionRegistration collectionRegistration
-
scheduledFuture
@Nullable private volatile java.util.concurrent.ScheduledFuture<?> scheduledFuture
-
-
Constructor Detail
-
PeriodicMetricReader
PeriodicMetricReader(MetricExporter exporter, long intervalNanos, java.util.concurrent.ScheduledExecutorService scheduler)
-
-
Method Detail
-
create
public static PeriodicMetricReader create(MetricExporter exporter)
Returns a newPeriodicMetricReaderwhich exports to theexporteronce every minute.
-
builder
public static PeriodicMetricReaderBuilder builder(MetricExporter exporter)
Returns a newPeriodicMetricReaderBuilder.
-
getAggregationTemporality
public AggregationTemporality getAggregationTemporality(InstrumentType instrumentType)
Description copied from interface:AggregationTemporalitySelectorReturn the aggregation temporality for theInstrumentType.- Specified by:
getAggregationTemporalityin interfaceAggregationTemporalitySelector
-
getDefaultAggregation
public Aggregation getDefaultAggregation(InstrumentType instrumentType)
Description copied from interface:MetricReaderReturn the default aggregation for theInstrumentType.- Specified by:
getDefaultAggregationin interfaceDefaultAggregationSelector- Specified by:
getDefaultAggregationin interfaceMetricReader- See Also:
DefaultAggregationSelector.getDefaultAggregation(InstrumentType)
-
getMemoryMode
public MemoryMode getMemoryMode()
Description copied from interface:MetricReaderReturns the memory mode used by this reader.- Specified by:
getMemoryModein interfaceMetricReader- Returns:
- The
MemoryModeused by this instance
-
forceFlush
public CompletableResultCode forceFlush()
Description copied from interface:MetricReaderRead and export the metrics.Called when
SdkMeterProvider.forceFlush()is called.- Specified by:
forceFlushin interfaceMetricReader- Returns:
- the result of the flush.
-
shutdown
public CompletableResultCode shutdown()
Description copied from interface:MetricReaderShuts down the metric reader.Called when
SdkMeterProvider.shutdown()is called.For pull based readers like prometheus, this should shut down the metric hosting endpoint or server doing such a job.
For push based readers like
MetricExporter, this should shut down any scheduler threads.- Specified by:
shutdownin interfaceMetricReader- Returns:
- the result of the shutdown.
-
register
public void register(CollectionRegistration collectionRegistration)
Description copied from interface:MetricReaderCalled bySdkMeterProvideron initialization to supply theMetricReaderwithMetricProducers used to collect metrics.MetricReaderimplementations callCollectionRegistration.collectAllMetrics()to read metrics.- Specified by:
registerin interfaceMetricReader
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
start
void start()
-
-