Metric
- class aws_cdk.aws_cloudwatch.Metric(*, metric_name, namespace, account=None, color=None, dimensions=None, dimensions_map=None, label=None, period=None, region=None, statistic=None, unit=None)
Bases:
object
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.
- ExampleMetadata:
infused
Example:
# fn: lambda.Function minute_error_rate = fn.metric_errors( statistic="avg", period=Duration.minutes(1), label="Lambda failure rate" )
- Parameters:
metric_name (
str
) – Name of the metric.namespace (
str
) – Namespace of the metric.account (
Optional
[str
]) – Account which this metric comes from. Default: - Deployment account.color (
Optional
[str
]) – The hex color code, prefixed with ‘#’ (e.g. ‘#00ff00’), to use when this metric is rendered on a graph. TheColor
class has a set of standard colors that can be used here. Default: - Automatic colordimensions (
Optional
[Mapping
[str
,Any
]]) – (deprecated) Dimensions of the metric. Default: - No dimensions.dimensions_map (
Optional
[Mapping
[str
,str
]]) – Dimensions of the metric. Default: - No dimensions.label (
Optional
[str
]) – Label for this metric when added to a Graph in a Dashboard. You can use dynamic labels to show summary information about the entire displayed time series in the legend. For example, if you use:: [max: ${MAX}] MyMetric As the metric label, the maximum value in the visible range will be shown next to the time series name in the graph’s legend. Default: - No labelperiod (
Optional
[Duration
]) – The period over which the specified statistic is applied. Default: Duration.minutes(5)region (
Optional
[str
]) – Region which this metric comes from. Default: - Deployment region.statistic (
Optional
[str
]) – What function to use for aggregating. Can be one of the following: - “Minimum” | “min” - “Maximum” | “max” - “Average” | “avg” - “Sum” | “sum” - “SampleCount | “n” - “pNN.NN” Default: Averageunit (
Optional
[Unit
]) – Unit used to filter the metric stream. Only refer to datums emitted to the metric stream with the given unit and ignore all others. Only useful when datums are being emitted to the same metric stream under different units. The default is to use all matric datums in the stream, regardless of unit, which is recommended in nearly all cases. CloudWatch does not honor this property for graphs. Default: - All metric datums in the given metric stream
Methods
- attach_to(scope)
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.
- Parameters:
scope (
IConstruct
) –- Return type:
- create_alarm(scope, id, *, evaluation_periods, threshold, actions_enabled=None, alarm_description=None, alarm_name=None, comparison_operator=None, datapoints_to_alarm=None, evaluate_low_sample_count_percentile=None, period=None, statistic=None, treat_missing_data=None)
Make a new Alarm for this metric.
Combines both properties that may adjust the metric (aggregation) as well as alarm properties.
- Parameters:
scope (
Construct
) –id (
str
) –evaluation_periods (
Union
[int
,float
]) – The number of periods over which data is compared to the specified threshold.threshold (
Union
[int
,float
]) – The value against which the specified statistic is compared.actions_enabled (
Optional
[bool
]) – Whether the actions for this alarm are enabled. Default: truealarm_description (
Optional
[str
]) – Description for the alarm. Default: No descriptionalarm_name (
Optional
[str
]) – Name of the alarm. Default: Automatically generated namecomparison_operator (
Optional
[ComparisonOperator
]) – Comparison to use to check if metric is breaching. Default: GreaterThanOrEqualToThresholddatapoints_to_alarm (
Union
[int
,float
,None
]) – The number of datapoints that must be breaching to trigger the alarm. This is used only if you are setting an “M out of N” alarm. In that case, this value is the M. For more information, see Evaluating an Alarm in the Amazon CloudWatch User Guide. Default:evaluationPeriods
evaluate_low_sample_count_percentile (
Optional
[str
]) – Specifies whether to evaluate the data and potentially change the alarm state if there are too few data points to be statistically significant. Used only for alarms that are based on percentiles. Default: - Not configured.period (
Optional
[Duration
]) – (deprecated) The period over which the specified statistic is applied. Cannot be used withMathExpression
objects. Default: - The period from the metricstatistic (
Optional
[str
]) – (deprecated) What function to use for aggregating. Can be one of the following: - “Minimum” | “min” - “Maximum” | “max” - “Average” | “avg” - “Sum” | “sum” - “SampleCount | “n” - “pNN.NN” Cannot be used withMathExpression
objects. Default: - The statistic from the metrictreat_missing_data (
Optional
[TreatMissingData
]) – Sets how this alarm is to handle missing data points. Default: TreatMissingData.Missing
- Return type:
- to_alarm_config()
(deprecated) Turn this metric object into an alarm configuration.
- Deprecated:
use toMetricConfig()
- Stability:
deprecated
- Return type:
- to_graph_config()
(deprecated) Turn this metric object into a graph configuration.
- Deprecated:
use toMetricConfig()
- Stability:
deprecated
- Return type:
- to_metric_config()
Inspect the details of the metric object.
- Return type:
- to_string()
Returns a string representation of an object.
- Return type:
str
- with_(*, account=None, color=None, dimensions=None, dimensions_map=None, label=None, period=None, region=None, statistic=None, unit=None)
Return a copy of Metric
with
properties changed.All properties except namespace and metricName can be changed.
- Parameters:
account (
Optional
[str
]) – Account which this metric comes from. Default: - Deployment account.color (
Optional
[str
]) – The hex color code, prefixed with ‘#’ (e.g. ‘#00ff00’), to use when this metric is rendered on a graph. TheColor
class has a set of standard colors that can be used here. Default: - Automatic colordimensions (
Optional
[Mapping
[str
,Any
]]) – (deprecated) Dimensions of the metric. Default: - No dimensions.dimensions_map (
Optional
[Mapping
[str
,str
]]) – Dimensions of the metric. Default: - No dimensions.label (
Optional
[str
]) –Label for this metric when added to a Graph in a Dashboard. You can use dynamic labels to show summary information about the entire displayed time series in the legend. For example, if you use:: [max: ${MAX}] MyMetric As the metric label, the maximum value in the visible range will be shown next to the time series name in the graph’s legend. Default: - No label
period (
Optional
[Duration
]) – The period over which the specified statistic is applied. Default: Duration.minutes(5)region (
Optional
[str
]) – Region which this metric comes from. Default: - Deployment region.statistic (
Optional
[str
]) – What function to use for aggregating. Can be one of the following: - “Minimum” | “min” - “Maximum” | “max” - “Average” | “avg” - “Sum” | “sum” - “SampleCount | “n” - “pNN.NN” Default: Averageunit (
Optional
[Unit
]) – Unit used to filter the metric stream. Only refer to datums emitted to the metric stream with the given unit and ignore all others. Only useful when datums are being emitted to the same metric stream under different units. The default is to use all matric datums in the stream, regardless of unit, which is recommended in nearly all cases. CloudWatch does not honor this property for graphs. Default: - All metric datums in the given metric stream
- Return type:
Attributes
- 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.
- label
Label for this metric when added to a Graph in a Dashboard.
- metric_name
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.
- warnings
Warnings attached to this metric.
Static Methods
- classmethod grant_put_metric_data(grantee)
Grant permissions to the given identity to write metrics.
- Parameters:
grantee (
IGrantable
) – The IAM identity to give permissions to.- Return type: