Class PeriodicMetricReader
java.lang.Object
io.opentelemetry.sdk.metrics.export.PeriodicMetricReader
- All Implemented Interfaces:
AggregationTemporalitySelector, DefaultAggregationSelector, MetricReader, Closeable, AutoCloseable
A
MetricReader which wraps a MetricExporter and automatically reads and exports
the metrics every export interval.
Register with SdkMeterProvider via SdkMeterProviderBuilder.registerMetricReader(MetricReader).
- Since:
- 1.14.0
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate CollectionRegistrationprivate final MetricExporterprivate final longprivate final Objectprivate static final Loggerprivate final PeriodicMetricReader.Scheduledprivate ScheduledFuture<?> private final ScheduledExecutorService -
Constructor Summary
ConstructorsConstructorDescriptionPeriodicMetricReader(MetricExporter exporter, long intervalNanos, ScheduledExecutorService scheduler) -
Method Summary
Modifier and TypeMethodDescriptionstatic PeriodicMetricReaderBuilderbuilder(MetricExporter exporter) Returns a newPeriodicMetricReaderBuilder.static PeriodicMetricReadercreate(MetricExporter exporter) Returns a newPeriodicMetricReaderwhich exports to theexporteronce every minute.Read and export the metrics.getAggregationTemporality(InstrumentType instrumentType) Return the aggregation temporality for theInstrumentType.getDefaultAggregation(InstrumentType instrumentType) Return the default aggregation for theInstrumentType.Returns the memory mode used by this reader.voidregister(CollectionRegistration collectionRegistration) Called bySdkMeterProvideron initialization to supply theMetricReaderwithMetricProducers used to collect metrics.shutdown()Shuts down the metric reader.(package private) voidstart()toString()Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface DefaultAggregationSelector
withMethods inherited from interface MetricReader
close
-
Field Details
-
logger
-
exporter
-
intervalNanos
private final long intervalNanos -
scheduler
-
scheduled
-
lock
-
collectionRegistration
-
scheduledFuture
-
-
Constructor Details
-
PeriodicMetricReader
PeriodicMetricReader(MetricExporter exporter, long intervalNanos, ScheduledExecutorService scheduler)
-
-
Method Details
-
create
Returns a newPeriodicMetricReaderwhich exports to theexporteronce every minute. -
builder
Returns a newPeriodicMetricReaderBuilder. -
getAggregationTemporality
Description copied from interface:AggregationTemporalitySelectorReturn the aggregation temporality for theInstrumentType.- Specified by:
getAggregationTemporalityin interfaceAggregationTemporalitySelector
-
getDefaultAggregation
Description copied from interface:MetricReaderReturn the default aggregation for theInstrumentType.- Specified by:
getDefaultAggregationin interfaceDefaultAggregationSelector- Specified by:
getDefaultAggregationin interfaceMetricReader- See Also:
-
getMemoryMode
Description copied from interface:MetricReaderReturns the memory mode used by this reader.- Specified by:
getMemoryModein interfaceMetricReader- Returns:
- The
MemoryModeused by this instance
-
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
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
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
-
start
void start()
-