aws-cdk-lib.aws_cloudwatch.MathExpression

class MathExpression

LanguageType name
.NETAmazon.CDK.AWS.CloudWatch.MathExpression
Gogithub.com/aws/aws-cdk-go/awscdk/v2/awscloudwatch#MathExpression
Javasoftware.amazon.awscdk.services.cloudwatch.MathExpression
Pythonaws_cdk.aws_cloudwatch.MathExpression
TypeScript (source)aws-cdk-lib » aws_cloudwatch » MathExpression

Implements IMetric

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.

Example

declare const fn: lambda.Function;

const allProblems = new cloudwatch.MathExpression({
  expression: "errors + throttles",
  usingMetrics: {
    errors: fn.metricErrors(),
    throttles: fn.metricThrottles(),
  }
});

Initializer

new MathExpression(props: MathExpressionProps)

Parameters

  • props MathExpressionProps

Properties

NameTypeDescription
expressionstringThe expression defining the metric.
periodDurationAggregation period of this metric.
usingMetrics{ [string]: IMetric }The metrics used in the expression as KeyValuePair <id, metric>.
color?stringThe 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.
label?stringLabel for this metric when added to a Graph.
searchAccount?stringAccount to evaluate search expressions within.
searchRegion?stringRegion to evaluate search expressions within.
warnings?string[]Warnings generated by this math expression.

expression

Type: string

The expression defining the metric.


period

Type: Duration

Aggregation period of this metric.


usingMetrics

Type: { [string]: IMetric }

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


color?

Type: string (optional)

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.


label?

Type: string (optional)

Label for this metric when added to a Graph.


searchAccount?

Type: string (optional)

Account to evaluate search expressions within.


searchRegion?

Type: string (optional)

Region to evaluate search expressions within.


warnings?

Type: string[] (optional)

Warnings generated by this math expression.

Methods

NameDescription
createAlarm(scope, id, props)Make a new Alarm for this metric.
toMetricConfig()Inspect the details of the metric object.
toString()Returns a string representation of an object.
with(props)Return a copy of Metric with properties changed.

createAlarm(scope, id, props)

public createAlarm(scope: Construct, id: string, props: CreateAlarmOptions): Alarm

Parameters

  • scope Construct
  • id string
  • props CreateAlarmOptions

Returns

  • Alarm

Make a new Alarm for this metric.

Combines both properties that may adjust the metric (aggregation) as well as alarm properties.


toMetricConfig()

public toMetricConfig(): MetricConfig

Returns

  • MetricConfig

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: MathExpressionOptions): MathExpression

Parameters

  • props MathExpressionOptions — The set of properties to change.

Returns

  • MathExpression

Return a copy of Metric with properties changed.

All properties except namespace and metricName can be changed.