class MathExpression
Language | Type name |
---|---|
![]() | Amazon.CDK.AWS.CloudWatch.MathExpression |
![]() | github.com/aws/aws-cdk-go/awscdk/v2/awscloudwatch#MathExpression |
![]() | software.amazon.awscdk.services.cloudwatch.MathExpression |
![]() | aws_cdk.aws_cloudwatch.MathExpression |
![]() | 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 matchmakingRuleSet: gamelift.MatchmakingRuleSet;
// Alarm that triggers when the per-second average of not placed matches exceed 10%
const ruleEvaluationRatio = new cloudwatch.MathExpression({
expression: '1 - (ruleEvaluationsPassed / ruleEvaluationsFailed)',
usingMetrics: {
ruleEvaluationsPassed: matchmakingRuleSet.metricRuleEvaluationsPassed({ statistic: cloudwatch.Statistic.SUM }),
ruleEvaluationsFailed: matchmakingRuleSet.metric('ruleEvaluationsFailed'),
},
});
new cloudwatch.Alarm(this, 'Alarm', {
metric: ruleEvaluationRatio,
threshold: 0.1,
evaluationPeriods: 3,
});
Initializer
new MathExpression(props: MathExpressionProps)
Parameters
- props
Math
Expression Props
Properties
Name | Type | Description |
---|---|---|
expression | string | The expression defining the metric. |
period | Duration | Aggregation period of this metric. |
using | { [string]: IMetric } | The metrics used in the expression as KeyValuePair <id, metric>. |
color? | string | 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? | string | Label for this metric when added to a Graph. |
search | string | Account to evaluate search expressions within. |
search | string | Region to evaluate search expressions within. |
warnings? | string[] | Warnings generated by this math expression. |
warnings | { [string]: 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?
⚠️ Deprecated: - use warningsV2
Type:
string[]
(optional)
Warnings generated by this math expression.
warningsV2?
Type:
{ [string]: string }
(optional)
Warnings generated by this math expression.
Methods
Name | Description |
---|---|
create | Make a new Alarm for this metric. |
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. |
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.
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: MathExpressionOptions): MathExpression
Parameters
- props
Math
— The set of properties to change.Expression Options
Returns
Return a copy of Metric with properties changed.
All properties except namespace and metricName can be changed.