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(boolean preserveDimensions)
Create a copy of the context
|
DimensionSet |
getDefaultDimensions() |
java.util.List<DimensionSet> |
getDimensions()
Get list of all dimensions including default dimensions
|
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,
StorageResolution storageResolution)
Add a metric measurement to the context with a storage resolution but without a unit.
|
void |
putMetric(java.lang.String key,
double value,
Unit unit)
Add a metric measurement to the context without a storage resolution.
|
void |
putMetric(java.lang.String key,
double value,
Unit unit,
StorageResolution storageResolution)
Add a metric measurement to the context.
|
void |
putProperty(java.lang.String name,
java.lang.Object value)
Add a property to this log entry.
|
void |
resetDimensions(boolean useDefault)
Reset the dimensions.
|
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(boolean useDefault,
DimensionSet... dimensionSets)
Update the dimensions.
|
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)
throws InvalidNamespaceException
InvalidNamespaceExceptionpublic java.lang.String getNamespace()
public void setNamespace(java.lang.String namespace)
throws InvalidNamespaceException
namespace - The new namespaceInvalidNamespaceException - if the namespace is invalidpublic 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,
StorageResolution storageResolution)
throws InvalidMetricException
metricContext.putMetric("Latency", 100, Unit.MILLISECONDS, StorageResolution.HIGH)
key - Name of the metricvalue - Value of the metricunit - The unit of the metricstorageResolution - The resolution of the metricInvalidMetricException - if the metric is invalidpublic void putMetric(java.lang.String key,
double value,
StorageResolution storageResolution)
throws InvalidMetricException
metricContext.putMetric("Latency", 100, StorageResolution.HIGH)
key - Name of the metricvalue - Value of the metricstorageResolution - The resolution of the metricInvalidMetricException - if the metric is invalidpublic void putMetric(java.lang.String key,
double value,
Unit unit)
throws InvalidMetricException
metricContext.putMetric("Latency", 100, Unit.MILLISECONDS)
key - Name of the metricvalue - Value of the metricunit - The unit of the metricInvalidMetricException - if the metric is invalidpublic void putMetric(java.lang.String key,
double value)
throws InvalidMetricException
metricContext.putMetric("Count", 10)
key - Name of the metricvalue - Value of the metricInvalidMetricException - if the metric is invalidpublic 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)
throws InvalidDimensionException,
DimensionSetExceededException
metricContext.putDimension("Dim", "Value" )
dimension - the name of the dimensionvalue - the value associated with the dimensionInvalidDimensionException - if the dimension is invalidDimensionSetExceededException - if the number of dimensions exceeds the limitpublic java.util.List<DimensionSet> getDimensions() throws DimensionSetExceededException
DimensionSetExceededException - if the number of dimensions exceeds the limitpublic void setDimensions(DimensionSet... dimensionSets)
dimensionSets - the dimensionSets to be setpublic void setDimensions(boolean useDefault,
DimensionSet... dimensionSets)
useDefault - indicates whether default dimensions should be useddimensionSets - the dimensionSets to setpublic void resetDimensions(boolean useDefault)
useDefault - indicates whether default dimensions should be usedpublic 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)
throws InvalidTimestampException
timestamp - value of timestamp to be setInvalidTimestampException - if the timestamp is invalidpublic MetricsContext createCopyWithContext(boolean preserveDimensions)
preserveDimensions - indicates whether default dimensions should be preservedpublic 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