MathExpression

class aws_cdk.aws_cloudwatch.MathExpression(*, expression, using_metrics=None, color=None, label=None, period=None, search_account=None, search_region=None)

Bases: object

A math expression built with metric(s) emitted by a service.

The math expression is a combination of an expression (x+y) and metrics to apply expression on. 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.

MathExpression can also be used for search expressions. In this case, it also optionally accepts a searchRegion and searchAccount property for cross-environment search expressions.

This class does not represent a resource, so hence is not a construct. Instead, MathExpression is an abstraction that makes it easy to specify metrics for use in both alarms and graphs.

ExampleMetadata:

infused

Example:

# fn: lambda.Function


all_problems = cloudwatch.MathExpression(
    expression="errors + throttles",
    using_metrics={
        "errors": fn.metric_errors(),
        "throttles": fn.metric_throttles()
    }
)
Parameters:
  • expression (str) – The expression defining the metric. When an expression contains a SEARCH function, it cannot be used within an Alarm.

  • using_metrics (Optional[Mapping[str, IMetric]]) – The metrics used in the expression, in a map. The key is the identifier that represents the given metric in the expression, and the value is the actual Metric object. Default: - Empty map.

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

  • label (Optional[str]) – Label for this expression when added to a Graph in a Dashboard. If this expression evaluates to more than one time series (for example, through the use of METRICS() or SEARCH() expressions), each time series will appear in the graph using a combination of the expression label and the individual metric label. Specify the empty string ('') to suppress the expression label and only keep the metric label. You can use dynamic labels to show summary information about the 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. If the math expression produces more than one time series, the maximum will be shown for each individual time series produce by this math expression. Default: - Expression value is used as label

  • period (Optional[Duration]) – The period over which the expression’s statistics are applied. This period overrides all periods in the metrics used in this math expression. Default: Duration.minutes(5)

  • search_account (Optional[str]) – Account to evaluate search expressions within. Specifying a searchAccount has no effect to the account used for metrics within the expression (passed via usingMetrics). Default: - Deployment account.

  • search_region (Optional[str]) – Region to evaluate search expressions within. Specifying a searchRegion has no effect to the region used for metrics within the expression (passed via usingMetrics). Default: - Deployment region.

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, 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: 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.

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

Return type:

Alarm

to_metric_config()

Inspect the details of the metric object.

Return type:

MetricConfig

to_string()

Returns a string representation of an object.

Return type:

str

with_(*, color=None, label=None, period=None, search_account=None, search_region=None)

Return a copy of Metric with properties changed.

All properties except namespace and metricName can be changed.

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

  • label (Optional[str]) –

    Label for this expression when added to a Graph in a Dashboard. If this expression evaluates to more than one time series (for example, through the use of METRICS() or SEARCH() expressions), each time series will appear in the graph using a combination of the expression label and the individual metric label. Specify the empty string ('') to suppress the expression label and only keep the metric label. You can use dynamic labels to show summary information about the 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. If the math expression produces more than one time series, the maximum will be shown for each individual time series produce by this math expression. Default: - Expression value is used as label

  • period (Optional[Duration]) – The period over which the expression’s statistics are applied. This period overrides all periods in the metrics used in this math expression. Default: Duration.minutes(5)

  • search_account (Optional[str]) – Account to evaluate search expressions within. Specifying a searchAccount has no effect to the account used for metrics within the expression (passed via usingMetrics). Default: - Deployment account.

  • search_region (Optional[str]) – Region to evaluate search expressions within. Specifying a searchRegion has no effect to the region used for metrics within the expression (passed via usingMetrics). Default: - Deployment region.

Return type:

MathExpression

Attributes

color

The hex color code, prefixed with ‘#’ (e.g. ‘#00ff00’), to use when this metric is rendered on a graph. The Color class has a set of standard colors that can be used here.

expression

The expression defining the metric.

label

Label for this metric when added to a Graph.

period

Aggregation period of this metric.

search_account

Account to evaluate search expressions within.

search_region

Region to evaluate search expressions within.

using_metrics

The metrics used in the expression as KeyValuePair <id, metric>.

warnings

(deprecated) Warnings generated by this math expression.

Deprecated:
  • use warningsV2

Stability:

deprecated

warnings_v2

Warnings generated by this math expression.