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
AMetricReader
which wraps aMetricExporter
and automatically reads and exports the metrics every export interval.Register with
SdkMeterProvider
viaSdkMeterProviderBuilder.registerMetricReader(MetricReader)
.- Since:
- 1.14.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
PeriodicMetricReader.Scheduled
-
Field Summary
Fields Modifier and Type Field Description private CollectionRegistration
collectionRegistration
private MetricExporter
exporter
private long
intervalNanos
private java.lang.Object
lock
private static java.util.logging.Logger
logger
private PeriodicMetricReader.Scheduled
scheduled
private java.util.concurrent.ScheduledFuture<?>
scheduledFuture
private java.util.concurrent.ScheduledExecutorService
scheduler
-
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 PeriodicMetricReaderBuilder
builder(MetricExporter exporter)
Returns a newPeriodicMetricReaderBuilder
.static PeriodicMetricReader
create(MetricExporter exporter)
Returns a newPeriodicMetricReader
which exports to theexporter
once every minute.CompletableResultCode
forceFlush()
Read and export the metrics.AggregationTemporality
getAggregationTemporality(InstrumentType instrumentType)
Return the aggregation temporality for theInstrumentType
.Aggregation
getDefaultAggregation(InstrumentType instrumentType)
Return the default aggregation for theInstrumentType
.MemoryMode
getMemoryMode()
Returns the memory mode used by this reader.void
register(CollectionRegistration collectionRegistration)
Called bySdkMeterProvider
on initialization to supply theMetricReader
withMetricProducer
s used to collect metrics.CompletableResultCode
shutdown()
Shuts down the metric reader.(package private) void
start()
java.lang.String
toString()
-
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 newPeriodicMetricReader
which exports to theexporter
once every minute.
-
builder
public static PeriodicMetricReaderBuilder builder(MetricExporter exporter)
Returns a newPeriodicMetricReaderBuilder
.
-
getAggregationTemporality
public AggregationTemporality getAggregationTemporality(InstrumentType instrumentType)
Description copied from interface:AggregationTemporalitySelector
Return the aggregation temporality for theInstrumentType
.- Specified by:
getAggregationTemporality
in interfaceAggregationTemporalitySelector
-
getDefaultAggregation
public Aggregation getDefaultAggregation(InstrumentType instrumentType)
Description copied from interface:MetricReader
Return the default aggregation for theInstrumentType
.- Specified by:
getDefaultAggregation
in interfaceDefaultAggregationSelector
- Specified by:
getDefaultAggregation
in interfaceMetricReader
- See Also:
DefaultAggregationSelector.getDefaultAggregation(InstrumentType)
-
getMemoryMode
public MemoryMode getMemoryMode()
Description copied from interface:MetricReader
Returns the memory mode used by this reader.- Specified by:
getMemoryMode
in interfaceMetricReader
- Returns:
- The
MemoryMode
used by this instance
-
forceFlush
public CompletableResultCode forceFlush()
Description copied from interface:MetricReader
Read and export the metrics.Called when
SdkMeterProvider.forceFlush()
is called.- Specified by:
forceFlush
in interfaceMetricReader
- Returns:
- the result of the flush.
-
shutdown
public CompletableResultCode shutdown()
Description copied from interface:MetricReader
Shuts 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:
shutdown
in interfaceMetricReader
- Returns:
- the result of the shutdown.
-
register
public void register(CollectionRegistration collectionRegistration)
Description copied from interface:MetricReader
Called bySdkMeterProvider
on initialization to supply theMetricReader
withMetricProducer
s used to collect metrics.MetricReader
implementations callCollectionRegistration.collectAllMetrics()
to read metrics.- Specified by:
register
in interfaceMetricReader
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
start
void start()
-
-