public class MetricsContext
extends java.lang.Object
| Constructor and Description |
|---|
MetricsContext() |
MetricsContext(software.amazon.cloudwatchlogs.emf.model.MetricDirective metricDirective) |
MetricsContext(software.amazon.cloudwatchlogs.emf.model.RootNode rootNode) |
MetricsContext(java.lang.String namespace,
java.util.Map<java.lang.String,java.lang.Object> properties,
java.util.List<DimensionSet> dimensionSets,
DimensionSet defaultDimensionSet) |
| Modifier and Type | Method and Description |
|---|---|
MetricsContext |
createCopyWithContext() |
DimensionSet |
getDefaultDimensions() |
java.util.List<DimensionSet> |
getDimensions() |
java.lang.String |
getNamespace() |
java.lang.Object |
getProperty(java.lang.String name) |
java.time.Instant |
getTimestamp() |
boolean |
hasDefaultDimensions() |
void |
putDimension(DimensionSet dimensionSet)
Add dimensions to the metric context.
|
void |
putDimension(java.lang.String dimension,
java.lang.String value)
Add a dimension set with single dimension-value entry to the metric context.
|
void |
putMetadata(java.lang.String key,
java.lang.Object value)
Add a key-value pair to the metadata
|
void |
putMetric(java.lang.String key,
double value)
Add a metric measurement to the context without a unit Multiple calls using the same key will
be stored as an array of scalar values.
|
void |
putMetric(java.lang.String key,
double value,
Unit unit)
Add a metric measurement to the context.
|
void |
putProperty(java.lang.String name,
java.lang.Object value)
Add a property to this log entry.
|
java.util.List<java.lang.String> |
serialize()
Serialize the metrics in this context to strings.
|
void |
setDefaultDimensions(DimensionSet dimensionSet)
Sets default dimensions for all other dimensions that get added to the context.
|
void |
setDimensions(DimensionSet... dimensionSets)
Update the dimensions.
|
void |
setNamespace(java.lang.String namespace)
Update the namespace with the parameter.
|
void |
setTimestamp(java.time.Instant timestamp)
Update timestamp field in the metadata
|
public MetricsContext()
public MetricsContext(software.amazon.cloudwatchlogs.emf.model.RootNode rootNode)
public MetricsContext(software.amazon.cloudwatchlogs.emf.model.MetricDirective metricDirective)
public MetricsContext(java.lang.String namespace,
java.util.Map<java.lang.String,java.lang.Object> properties,
java.util.List<DimensionSet> dimensionSets,
DimensionSet defaultDimensionSet)
public java.lang.String getNamespace()
public void setNamespace(java.lang.String namespace)
namespace - The new namespacepublic DimensionSet getDefaultDimensions()
public void setDefaultDimensions(DimensionSet dimensionSet)
dimensionSet - the DimensionSet to be the defaultpublic boolean hasDefaultDimensions()
public void putMetric(java.lang.String key,
double value,
Unit unit)
metricContext.putMetric("Latency", 100, Unit.MILLISECONDS)
key - Name of the metricvalue - Value of the metricunit - The unit of the metricpublic void putMetric(java.lang.String key,
double value)
metricContext.putMetric("Count", 10)
key - Name of the metricvalue - Value of the metricpublic void putProperty(java.lang.String name,
java.lang.Object value)
metricContext.putProperty("Location", 'US')
name - Name of the propertyvalue - Value of the propertypublic java.lang.Object getProperty(java.lang.String name)
public void putDimension(DimensionSet dimensionSet)
metricContext.putDimension(DimensionSet.of("Dim", "Value" ))
dimensionSet - the dimensions set to addpublic void putDimension(java.lang.String dimension,
java.lang.String value)
metricContext.putDimension("Dim", "Value" )
dimension - the name of the dimensionvalue - the value associated with the dimensionpublic java.util.List<DimensionSet> getDimensions()
public void setDimensions(DimensionSet... dimensionSets)
dimensionSets - the dimensionSets to be setpublic void putMetadata(java.lang.String key,
java.lang.Object value)
key - the name of the keyvalue - the value associated with the keypublic java.time.Instant getTimestamp()
public void setTimestamp(java.time.Instant timestamp)
timestamp - value of timestamp to be setpublic MetricsContext createCopyWithContext()
public java.util.List<java.lang.String> serialize()
throws com.fasterxml.jackson.core.JsonProcessingException
If a metric has more than 100 data points, we also split the metric.
com.fasterxml.jackson.core.JsonProcessingException - if there's any object that cannot be serialized