Package com.newrelic.telemetry.metrics
Class MetricBuffer
- java.lang.Object
-
- com.newrelic.telemetry.metrics.MetricBuffer
-
public final class MetricBuffer extends java.lang.Object
A buffer for collectingMetrics
.One instance of this class can collect many
Metrics
. To send them to the Metrics API, callcreateBatch()
and thenMetricBatchSender.sendBatch(MetricBatch)
.This class is thread-safe.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MetricBuffer.Builder
-
Constructor Summary
Constructors Constructor Description MetricBuffer(Attributes commonAttributes)
Create a new buffer with the provided common set of attributes.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addMetric(Metric metric)
Append aMetric
to this buffer, to be sent in the nextMetricBatch
.static MetricBuffer.Builder
builder()
Returns a new Builder instance for help with creating new MetricBatch instancesMetricBatch
createBatch()
Creates a newMetricBatch
from the contents of this buffer, then clears the contents of this buffer.boolean
equals(java.lang.Object o)
int
hashCode()
java.lang.String
toString()
-
-
-
Constructor Detail
-
MetricBuffer
public MetricBuffer(Attributes commonAttributes)
Create a new buffer with the provided common set of attributes.- Parameters:
commonAttributes
- These attributes will be appended (by the New Relic backend) to everyMetric
in this buffer.
-
-
Method Detail
-
addMetric
public void addMetric(Metric metric)
Append aMetric
to this buffer, to be sent in the nextMetricBatch
.- Parameters:
metric
- The newMetric
instance to be sent.
-
createBatch
public MetricBatch createBatch()
Creates a newMetricBatch
from the contents of this buffer, then clears the contents of this buffer.Metrics
added to this buffer by other threads during this method call will either be added to theMetricBatch
being created, or will be saved for the nextMetricBatch
.- Returns:
- A new
MetricBatch
with an immutable collection ofMetrics
.
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
builder
public static MetricBuffer.Builder builder()
Returns a new Builder instance for help with creating new MetricBatch instances- Returns:
- a new instance of MetricBatch.Builder
-
-