Metric Class
A metric emitted by a service.
The metric is a combination of a metric identifier (namespace, name and dimensions) and an aggregation function (statistic, period and unit).
It also contains metadata which is used only in graphs, such as color and label. It makes sense to embed this in here, so that compound constructs can attach that metadata to metrics they expose.
This class does not represent a resource, so hence is not a construct. Instead, Metric is an abstraction that makes it easy to specify metrics for use in both alarms and graphs.
Example
declare const serverlessCache: elasticache.ServerlessCache;
// The 5 minutes average of the total number of successful read-only key lookups in the cache.
const cacheHits = serverlessCache.metricCacheHitCount();
// The 5 minutes average of the total number of bytes used by the data stored in the cache.
const bytesUsedForCache = serverlessCache.metricDataStored();
// The 5 minutes average of the total number of ElastiCacheProcessingUnits (ECPUs) consumed by the requests executed on the cache.
const elastiCacheProcessingUnits = serverlessCache.metricProcessingUnitsConsumed();
// Create an alarm for ECPUs.
elastiCacheProcessingUnits.createAlarm(this, 'ElastiCacheProcessingUnitsAlarm', {
threshold: 50,
evaluationPeriods: 1,
});
# serverless_cache: elasticache.ServerlessCache
# The 5 minutes average of the total number of successful read-only key lookups in the cache.
cache_hits = serverless_cache.metric_cache_hit_count()
# The 5 minutes average of the total number of bytes used by the data stored in the cache.
bytes_used_for_cache = serverless_cache.metric_data_stored()
# The 5 minutes average of the total number of ElastiCacheProcessingUnits (ECPUs) consumed by the requests executed on the cache.
elasti_cache_processing_units = serverless_cache.metric_processing_units_consumed()
# Create an alarm for ECPUs.
elasti_cache_processing_units.create_alarm(self, "ElastiCacheProcessingUnitsAlarm",
threshold=50,
evaluation_periods=1
)
ServerlessCache serverlessCache;
// The 5 minutes average of the total number of successful read-only key lookups in the cache.
Metric cacheHits = serverlessCache.metricCacheHitCount();
// The 5 minutes average of the total number of bytes used by the data stored in the cache.
Metric bytesUsedForCache = serverlessCache.metricDataStored();
// The 5 minutes average of the total number of ElastiCacheProcessingUnits (ECPUs) consumed by the requests executed on the cache.
Metric elastiCacheProcessingUnits = serverlessCache.metricProcessingUnitsConsumed();
// Create an alarm for ECPUs.
elastiCacheProcessingUnits.createAlarm(this, "ElastiCacheProcessingUnitsAlarm", CreateAlarmOptions.builder()
.threshold(50)
.evaluationPeriods(1)
.build());
// Install: dotnet add package Amazon.CDK.Lib
ServerlessCache serverlessCache;
// The 5 minutes average of the total number of successful read-only key lookups in the cache.
var cacheHits = serverlessCache.MetricCacheHitCount();
// The 5 minutes average of the total number of bytes used by the data stored in the cache.
var bytesUsedForCache = serverlessCache.MetricDataStored();
// The 5 minutes average of the total number of ElastiCacheProcessingUnits (ECPUs) consumed by the requests executed on the cache.
var elastiCacheProcessingUnits = serverlessCache.MetricProcessingUnitsConsumed();
// Create an alarm for ECPUs.
elastiCacheProcessingUnits.CreateAlarm(this, "ElastiCacheProcessingUnitsAlarm", new CreateAlarmOptions {
Threshold = 50,
EvaluationPeriods = 1
});
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var serverlessCache ServerlessCache
// The 5 minutes average of the total number of successful read-only key lookups in the cache.
cacheHits := serverlessCache.MetricCacheHitCount()
// The 5 minutes average of the total number of bytes used by the data stored in the cache.
bytesUsedForCache := serverlessCache.MetricDataStored()
// The 5 minutes average of the total number of ElastiCacheProcessingUnits (ECPUs) consumed by the requests executed on the cache.
elastiCacheProcessingUnits := serverlessCache.MetricProcessingUnitsConsumed()
// Create an alarm for ECPUs.
elastiCacheProcessingUnits.CreateAlarm(this, jsii.String("ElastiCacheProcessingUnitsAlarm"), &CreateAlarmOptions{
Threshold: jsii.Number(50),
EvaluationPeriods: jsii.Number(1),
})
Initializer
new Metric(props: MetricProps)
Metric(props: MetricProps)
new Metric(MetricProps props)
new Metric(MetricProps props)
NewMetric(Props MetricProps)
Properties
dimensions{ [key: string]: any }dimensionstyping.Mapping[str, Any]dimensionsMap<String, Object>DimensionsIDictionary<string, object>Dimensions*map[string]interface{}#warningsstring[]warningstyping.List[str]warningsList<String>Warningsstring[]Warnings*[]*stringdeprecated#warningsV2{ [key: string]: string }warnings_v2typing.Mapping[str, str]warningsV2Map<String, String>WarningsV2IDictionary<string, string>WarningsV2*map[string]*string#Methods
anomalyDetectionFor(props: AnomalyDetectionMetricOptions): MathExpression@staticmethod def anomaly_detection_for(props: AnomalyDetectionMetricOptions) -> MathExpressionpublic static MathExpression anomalyDetectionFor(AnomalyDetectionMetricOptions props)public static MathExpression AnomalyDetectionFor(AnomalyDetectionMetricOptions props)func AnomalyDetectionFor(Props AnomalyDetectionMetricOptions) MathExpressionstatic#1 parameter · returns
Parameters
propspropspropspropsProps— The anomaly detection alarm properties.
Returns: An anomaly detection metric
attachTo(scope: IConstruct): Metric // chainabledef attach_to(self, scope: IConstruct) -> Metricpublic Metric attachTo(IConstruct scope)public Metric AttachTo(IConstruct scope)func AttachTo(Scope IConstruct) Metric#notes
Returns a Metric object that uses the account and region from the Stack the given construct is defined in. If the metric is subsequently used in a Dashboard or Alarm in a different Stack defined in a different account or region, the appropriate 'region' and 'account' fields will be added to it.
If the scope we attach to is in an environment-agnostic stack, nothing is done and the same Metric object is returned.
createAlarm(scope: Construct, id: string, props: CreateAlarmOptions): Alarmdef create_alarm(self, scope: Construct, id: str, props: CreateAlarmOptions) -> Alarmpublic Alarm createAlarm(Construct scope, String id, CreateAlarmOptions props)public Alarm CreateAlarm(Construct scope, string id, CreateAlarmOptions props)func CreateAlarm(Scope Construct, Id *string, Props CreateAlarmOptions) Alarm#Combines both properties that may adjust the metric (aggregation) as well as alarm properties.
grantPutMetricData(grantee: IGrantable): Grant@staticmethod def grant_put_metric_data(grantee: IGrantable) -> Grantpublic static Grant grantPutMetricData(IGrantable grantee)public static Grant GrantPutMetricData(IGrantable grantee)func GrantPutMetricData(Grantee IGrantable) Grantstatic#1 parameter
Parameters
granteegranteegranteegranteeGrantee— The IAM identity to give permissions to.
toMetricConfig(): MetricConfigdef to_metric_config(self, ) -> MetricConfigpublic MetricConfig toMetricConfig()public MetricConfig ToMetricConfig()func ToMetricConfig() MetricConfig#toString(): stringdef to_string(self, ) -> strpublic String toString()public string ToString()func ToString() *string#with(props: MetricOptions): Metric // chainabledef with(self, props: MetricOptions) -> Metricpublic Metric with(MetricOptions props)public Metric With(MetricOptions props)func With(Props MetricOptions) Metric#All properties except namespace and metricName can be changed.
1 parameter
Parameters
propspropspropspropsProps— The set of properties to change.