Class Metric
A metric emitted by a service.
Implements
Namespace: Amazon.CDK.AWS.CloudWatch
Assembly: Amazon.CDK.Lib.dll
Syntax (csharp)
public class Metric : DeputyBase, IMetric
Syntax (vb)
Public Class Metric Inherits DeputyBase Implements IMetric
Remarks
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.
ExampleMetadata: infused
Examples
// Create a metric
var metric = new Metric(new MetricProps {
Namespace = "AWS/EC2",
MetricName = "CPUUtilization",
Statistic = "Average",
Period = Duration.Hours(1)
});
// Create an anomaly detection alarm
var alarm = new AnomalyDetectionAlarm(this, "AnomalyAlarm", new AnomalyDetectionAlarmProps {
Metric = metric,
EvaluationPeriods = 1,
// Number of standard deviations for the band (default: 2)
StdDevs = 2,
// Alarm outside on either side of the band, or just below or above it (default: outside)
ComparisonOperator = ComparisonOperator.LESS_THAN_LOWER_OR_GREATER_THAN_UPPER_THRESHOLD,
AlarmDescription = "Alarm when metric is outside the expected band"
});
Synopsis
Constructors
| Metric(IMetricProps) | A metric emitted by a service. |
Properties
| Account | Account which this metric comes from. |
| Color | The hex color code used when this metric is rendered on a graph. |
| Dimensions | Dimensions of this metric. |
| Id | Unique identifier for this metric when used in dashboard widgets. |
| Label | Label for this metric when added to a Graph in a Dashboard. |
| MetricName | Name of this metric. |
| Namespace | Namespace of this metric. |
| Period | Period of this metric. |
| Region | Region which this metric comes from. |
| Statistic | Statistic of this metric. |
| Unit | Unit of the metric. |
| Visible | Whether this metric should be visible in dashboard graphs. |
| Warnings | (deprecated) Warnings attached to this metric. |
| WarningsV2 | Warnings attached to this metric. |
Methods
| AnomalyDetectionFor(IAnomalyDetectionMetricOptions) | Creates an anomaly detection metric from the provided metric. |
| AttachTo(IConstruct) | Attach the metric object to the given construct scope. |
| CreateAlarm(Construct, string, ICreateAlarmOptions) | Make a new Alarm for this metric. |
| GrantPutMetricData(IGrantable) | Grant permissions to the given identity to write metrics. |
| ToMetricConfig() | Inspect the details of the metric object. |
| ToString() | Returns a string representation of an object. |
| With(IMetricOptions) | Return a copy of Metric |
Constructors
Metric(IMetricProps)
A metric emitted by a service.
public Metric(IMetricProps props)
Parameters
- props IMetricProps
Remarks
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.
ExampleMetadata: infused
Examples
// Create a metric
var metric = new Metric(new MetricProps {
Namespace = "AWS/EC2",
MetricName = "CPUUtilization",
Statistic = "Average",
Period = Duration.Hours(1)
});
// Create an anomaly detection alarm
var alarm = new AnomalyDetectionAlarm(this, "AnomalyAlarm", new AnomalyDetectionAlarmProps {
Metric = metric,
EvaluationPeriods = 1,
// Number of standard deviations for the band (default: 2)
StdDevs = 2,
// Alarm outside on either side of the band, or just below or above it (default: outside)
ComparisonOperator = ComparisonOperator.LESS_THAN_LOWER_OR_GREATER_THAN_UPPER_THRESHOLD,
AlarmDescription = "Alarm when metric is outside the expected band"
});
Properties
Account
Account which this metric comes from.
public virtual string? Account { get; }
Property Value
Remarks
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.
ExampleMetadata: infused
Color
The hex color code used when this metric is rendered on a graph.
public virtual string? Color { get; }
Property Value
Remarks
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.
ExampleMetadata: infused
Dimensions
Dimensions of this metric.
public virtual IDictionary<string, object>? Dimensions { get; }
Property Value
Remarks
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.
ExampleMetadata: infused
Id
Unique identifier for this metric when used in dashboard widgets.
public virtual string? Id { get; }
Property Value
Remarks
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.
ExampleMetadata: infused
Label
Label for this metric when added to a Graph in a Dashboard.
public virtual string? Label { get; }
Property Value
Remarks
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.
ExampleMetadata: infused
MetricName
Name of this metric.
public virtual string MetricName { get; }
Property Value
Remarks
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.
ExampleMetadata: infused
Namespace
Namespace of this metric.
public virtual string Namespace { get; }
Property Value
Remarks
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.
ExampleMetadata: infused
Period
Period of this metric.
public virtual Duration Period { get; }
Property Value
Remarks
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.
ExampleMetadata: infused
Region
Region which this metric comes from.
public virtual string? Region { get; }
Property Value
Remarks
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.
ExampleMetadata: infused
Statistic
Statistic of this metric.
public virtual string Statistic { get; }
Property Value
Remarks
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.
ExampleMetadata: infused
Unit
Unit of the metric.
public virtual Unit? Unit { get; }
Property Value
Unit?
Remarks
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.
ExampleMetadata: infused
Visible
Whether this metric should be visible in dashboard graphs.
public virtual bool? Visible { get; }
Property Value
bool?
Remarks
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.
ExampleMetadata: infused
Warnings
(deprecated) Warnings attached to this metric.
[Obsolete("- use warningsV2")]
public virtual string[]? Warnings { get; }
Property Value
string[]
Remarks
Stability: Deprecated
WarningsV2
Warnings attached to this metric.
public virtual IDictionary<string, string>? WarningsV2 { get; }
Property Value
Remarks
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.
ExampleMetadata: infused
Methods
AnomalyDetectionFor(IAnomalyDetectionMetricOptions)
Creates an anomaly detection metric from the provided metric.
public static MathExpression AnomalyDetectionFor(IAnomalyDetectionMetricOptions props)
Parameters
- props IAnomalyDetectionMetricOptions
The anomaly detection alarm properties.
Returns
An anomaly detection metric
Remarks
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.
ExampleMetadata: infused
AttachTo(IConstruct)
Attach the metric object to the given construct scope.
public virtual Metric AttachTo(IConstruct scope)
Parameters
- scope IConstruct
Returns
Remarks
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(Construct, string, ICreateAlarmOptions)
Make a new Alarm for this metric.
public virtual Alarm CreateAlarm(Construct scope, string id, ICreateAlarmOptions props)
Parameters
- scope Construct
- id string
- props ICreateAlarmOptions
Returns
Remarks
Combines both properties that may adjust the metric (aggregation) as well as alarm properties.
GrantPutMetricData(IGrantable)
Grant permissions to the given identity to write metrics.
public static Grant GrantPutMetricData(IGrantable grantee)
Parameters
- grantee IGrantable
The IAM identity to give permissions to.
Returns
Remarks
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.
ExampleMetadata: infused
ToMetricConfig()
Inspect the details of the metric object.
public virtual IMetricConfig ToMetricConfig()
Returns
Remarks
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.
ExampleMetadata: infused
ToString()
Returns a string representation of an object.
public override string ToString()
Returns
Remarks
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.
ExampleMetadata: infused
With(IMetricOptions)
Return a copy of Metric with properties changed.
public virtual Metric With(IMetricOptions props)
Parameters
- props IMetricOptions
The set of properties to change.
Returns
Remarks
All properties except namespace and metricName can be changed.