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.
| Source | aws-cloudwatch/lib/metric.ts |
|---|---|
| Type last changed |
Example
declare const instance: rds.IDatabaseInstance;
const metrics = rds.DatabaseInstanceMetrics.fromDatabaseInstance(instance);
// How far a read replica lags behind its source (average over 5 minutes)
const replicaLag = metrics.replicaLag();
// The average amount of time taken per disk I/O read operation (average over 1 minute)
const readLatency = metrics.readLatency({ period: Duration.seconds(60) });
// Any other metric, such as an engine-specific one
const binLogDiskUsage = metrics.metric('BinLogDiskUsage', { statistic: 'Maximum' });
# instance: rds.IDatabaseInstance
metrics = rds.DatabaseInstanceMetrics.from_database_instance(instance)
# How far a read replica lags behind its source (average over 5 minutes)
replica_lag = metrics.replica_lag()
# The average amount of time taken per disk I/O read operation (average over 1 minute)
read_latency = metrics.read_latency(period=Duration.seconds(60))
# Any other metric, such as an engine-specific one
bin_log_disk_usage = metrics.metric("BinLogDiskUsage", statistic="Maximum")
IDatabaseInstance instance;
DatabaseInstanceMetrics metrics = DatabaseInstanceMetrics.fromDatabaseInstance(instance);
// How far a read replica lags behind its source (average over 5 minutes)
Metric replicaLag = metrics.replicaLag();
// The average amount of time taken per disk I/O read operation (average over 1 minute)
Metric readLatency = metrics.readLatency(MetricOptions.builder().period(Duration.seconds(60)).build());
// Any other metric, such as an engine-specific one
Metric binLogDiskUsage = metrics.metric("BinLogDiskUsage", MetricOptions.builder().statistic("Maximum").build());
// Install: dotnet add package Amazon.CDK.Lib
IDatabaseInstance instance;
var metrics = DatabaseInstanceMetrics.FromDatabaseInstance(instance);
// How far a read replica lags behind its source (average over 5 minutes)
var replicaLag = metrics.ReplicaLag();
// The average amount of time taken per disk I/O read operation (average over 1 minute)
var readLatency = metrics.ReadLatency(new MetricOptions { Period = Duration.Seconds(60) });
// Any other metric, such as an engine-specific one
var binLogDiskUsage = metrics.Metric("BinLogDiskUsage", new MetricOptions { Statistic = "Maximum" });
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var instance IDatabaseInstance
metrics := rds.DatabaseInstanceMetrics_FromDatabaseInstance(instance)
// How far a read replica lags behind its source (average over 5 minutes)
replicaLag := metrics.ReplicaLag()
// The average amount of time taken per disk I/O read operation (average over 1 minute)
readLatency := metrics.ReadLatency(&MetricOptions{
Period: awscdk.Duration_Seconds(jsii.Number(60)),
})
// Any other metric, such as an engine-specific one
binLogDiskUsage := metrics.Metric(jsii.String("BinLogDiskUsage"), &MetricOptions{
Statistic: jsii.String("Maximum"),
})
Initializer
new Metric(props: MetricProps)
Metric(props: MetricProps)
new Metric(MetricProps props)
new Metric(MetricProps props)
NewMetric(Props MetricProps)
Properties
accountmay be undefinedstringaccountmay be undefinedstraccountmay be undefinedStringAccountmay be undefinedstringAccountmay be undefined*string #colormay be undefinedstringcolormay be undefinedstrcolormay be undefinedStringColormay be undefinedstringColormay be undefined*string #dimensionsmay be undefined{ [key: string]: any }dimensionsmay be undefinedtyping.Mapping[str, Any]dimensionsmay be undefinedMap<String, Object>Dimensionsmay be undefinedIDictionary<string, object>Dimensionsmay be undefined*map[string]interface{} #idmay be undefinedstringidmay be undefinedstridmay be undefinedStringIdmay be undefinedstringIdmay be undefined*string #labelmay be undefinedstringlabelmay be undefinedstrlabelmay be undefinedStringLabelmay be undefinedstringLabelmay be undefined*string #regionmay be undefinedstringregionmay be undefinedstrregionmay be undefinedStringRegionmay be undefinedstringRegionmay be undefined*string #unitmay be undefinedUnitunitmay be undefinedUnitunitmay be undefinedUnitUnitmay be undefinedUnitUnitmay be undefinedUnit #visiblemay be undefinedbooleanvisiblemay be undefinedboolvisiblemay be undefinedBooleanVisiblemay be undefinedboolVisiblemay be undefined*bool #warningsmay be undefinedstring[]warningsmay be undefinedtyping.List[str]warningsmay be undefinedList<String>Warningsmay be undefinedstring[]Warningsmay be undefined*[]*string deprecated #warningsV2may be undefined{ [key: string]: string }warnings_v2may be undefinedtyping.Mapping[str, str]warningsV2may be undefinedMap<String, String>WarningsV2may be undefinedIDictionary<string, string>WarningsV2may be undefined*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) MathExpression static #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) Grant static #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.