Metric

class aws_cdk.aws_cloudwatch.Metric(*, metric_name, namespace, color=None, dimensions=None, label=None, period=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.

__init__(*, metric_name, namespace, color=None, dimensions=None, label=None, period=None, statistic=None, unit=None)
Parameters
  • props

  • metric_name (str) – Name of the metric.

  • namespace (str) – Namespace of the metric.

  • color (Optional[str]) – Color for this metric when added to a Graph in a Dashboard.

  • dimensions (Optional[Mapping[str, Any]]) – Dimensions of the metric. Default: - No dimensions.

  • label (Optional[str]) – Label for this metric when added to a Graph in a Dashboard.

  • period (Optional[Duration]) – The period over which the specified statistic is applied. Default: Duration.minutes(5)

  • 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: Average

  • unit (Optional[Unit]) – Unit for the metric that is associated with the alarm.

Return type

None

Methods

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) –

  • props

  • 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: true

  • alarm_description (Optional[str]) – Description for the alarm. Default: No description

  • alarm_name (Optional[str]) – Name of the alarm. Default: Automatically generated name

  • comparison_operator (Optional[ComparisonOperator]) – Comparison to use to check if metric is breaching. Default: GreaterThanOrEqualToThreshold

  • datapoints_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]) – The period over which the specified statistic is applied. Default: Duration.minutes(5)

  • 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: Average

  • treat_missing_data (Optional[TreatMissingData]) – Sets how this alarm is to handle missing data points. Default: TreatMissingData.Missing

Return type

Alarm

to_alarm_config()

Turn this metric object into an alarm configuration.

Return type

MetricAlarmConfig

to_graph_config()

Turn this metric object into a graph configuration.

Return type

MetricGraphConfig

to_string()

Returns a string representation of an object.

Return type

str

with_(*, color=None, dimensions=None, label=None, period=None, statistic=None, unit=None)

Return a copy of Metric with properties changed.

All properties except namespace and metricName can be changed.

Parameters
  • props – The set of properties to change.

  • color (Optional[str]) – Color for this metric when added to a Graph in a Dashboard.

  • dimensions (Optional[Mapping[str, Any]]) – Dimensions of the metric. Default: - No dimensions.

  • label (Optional[str]) – Label for this metric when added to a Graph in a Dashboard.

  • period (Optional[Duration]) – The period over which the specified statistic is applied. Default: Duration.minutes(5)

  • 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: Average

  • unit (Optional[Unit]) – Unit for the metric that is associated with the alarm.

Return type

Metric

Attributes

color
Return type

Optional[str]

dimensions
Return type

Optional[Mapping[str, Any]]

label
Return type

Optional[str]

metric_name
Return type

str

namespace
Return type

str

period
Return type

Duration

statistic
Return type

str

unit
Return type

Optional[Unit]

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

Grant