class Metric
Language | Type name |
---|---|
.NET | Amazon.CDK.AWS.CloudWatch.Metric |
Java | software.amazon.awscdk.services.cloudwatch.Metric |
Python | aws_cdk.aws_cloudwatch.Metric |
TypeScript (source) | @aws-cdk/aws-cloudwatch » Metric |
Implements
IMetric
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 fn: lambda.Function;
const minuteErrorRate = fn.metricErrors({
statistic: 'avg',
period: Duration.minutes(1),
label: 'Lambda failure rate'
});
Initializer
new Metric(props: MetricProps)
Parameters
- props
Metric
Props
Properties
Name | Type | Description |
---|---|---|
metric | string | Name of this metric. |
namespace | string | Namespace of this metric. |
period | Duration | Period of this metric. |
statistic | string | Statistic of this metric. |
account? | string | Account which this metric comes from. |
color? | string | The hex color code used when this metric is rendered on a graph. |
dimensions? | { [string]: any } | Dimensions of this metric. |
label? | string | Label for this metric when added to a Graph in a Dashboard. |
region? | string | Region which this metric comes from. |
unit? | Unit | Unit of the metric. |
warnings? | string[] | Warnings attached to this metric. |
metricName
Type:
string
Name of this metric.
namespace
Type:
string
Namespace of this metric.
period
Type:
Duration
Period of this metric.
statistic
Type:
string
Statistic of this metric.
account?
Type:
string
(optional)
Account which this metric comes from.
color?
Type:
string
(optional)
The hex color code used when this metric is rendered on a graph.
dimensions?
Type:
{ [string]: any }
(optional)
Dimensions of this metric.
label?
Type:
string
(optional)
Label for this metric when added to a Graph in a Dashboard.
region?
Type:
string
(optional)
Region which this metric comes from.
unit?
Type:
Unit
(optional)
Unit of the metric.
warnings?
Type:
string[]
(optional)
Warnings attached to this metric.
Methods
Name | Description |
---|---|
attach | Attach the metric object to the given construct scope. |
create | Make a new Alarm for this metric. |
to | Turn this metric object into an alarm configuration. |
to | Turn this metric object into a graph configuration. |
to | Inspect the details of the metric object. |
to | Returns a string representation of an object. |
with(props) | Return a copy of Metric with properties changed. |
static grant | Grant permissions to the given identity to write metrics. |
attachTo(scope)
public attachTo(scope: IConstruct): Metric
Parameters
- scope
IConstruct
Returns
Attach the metric object to the given construct scope.
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, id, props)
public createAlarm(scope: Construct, id: string, props: CreateAlarmOptions): Alarm
Parameters
- scope
Construct
- id
string
- props
Create
Alarm Options
Returns
Make a new Alarm for this metric.
Combines both properties that may adjust the metric (aggregation) as well as alarm properties.
toAlarmConfig()
public toAlarmConfig(): MetricAlarmConfig
⚠️ Deprecated: use toMetricConfig()
Returns
Turn this metric object into an alarm configuration.
toGraphConfig()
public toGraphConfig(): MetricGraphConfig
⚠️ Deprecated: use toMetricConfig()
Returns
Turn this metric object into a graph configuration.
toMetricConfig()
public toMetricConfig(): MetricConfig
Returns
Inspect the details of the metric object.
toString()
public toString(): string
Returns
string
Returns a string representation of an object.
with(props)
public with(props: MetricOptions): Metric
Parameters
- props
Metric
— The set of properties to change.Options
Returns
Return a copy of Metric with
properties changed.
All properties except namespace and metricName can be changed.
static grantPutMetricData(grantee)
public static grantPutMetricData(grantee: IGrantable): Grant
Parameters
- grantee
IGrantable
— The IAM identity to give permissions to.
Returns
Grant permissions to the given identity to write metrics.