MathExpression Class
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,
});
# matchmaking_rule_set: gamelift.MatchmakingRuleSet
# Alarm that triggers when the per-second average of not placed matches exceed 10%
rule_evaluation_ratio = cloudwatch.MathExpression(
expression="1 - (ruleEvaluationsPassed / ruleEvaluationsFailed)",
using_metrics={
"rule_evaluations_passed": matchmaking_rule_set.metric_rule_evaluations_passed(statistic=cloudwatch.Statistic.SUM),
"rule_evaluations_failed": matchmaking_rule_set.metric("ruleEvaluationsFailed")
}
)
cloudwatch.Alarm(self, "Alarm",
metric=rule_evaluation_ratio,
threshold=0.1,
evaluation_periods=3
)
MatchmakingRuleSet matchmakingRuleSet;
// Alarm that triggers when the per-second average of not placed matches exceed 10%
MathExpression ruleEvaluationRatio = MathExpression.Builder.create()
.expression("1 - (ruleEvaluationsPassed / ruleEvaluationsFailed)")
.usingMetrics(Map.of(
"ruleEvaluationsPassed", matchmakingRuleSet.metricRuleEvaluationsPassed(MetricOptions.builder().statistic(Statistic.SUM).build()),
"ruleEvaluationsFailed", matchmakingRuleSet.metric("ruleEvaluationsFailed")))
.build();
Alarm.Builder.create(this, "Alarm")
.metric(ruleEvaluationRatio)
.threshold(0.1)
.evaluationPeriods(3)
.build();
// Install: dotnet add package Amazon.CDK.Lib
MatchmakingRuleSet matchmakingRuleSet;
// Alarm that triggers when the per-second average of not placed matches exceed 10%
var ruleEvaluationRatio = new MathExpression(new MathExpressionProps {
Expression = "1 - (ruleEvaluationsPassed / ruleEvaluationsFailed)",
UsingMetrics = new Dictionary<string, IMetric> {
{ "ruleEvaluationsPassed", matchmakingRuleSet.MetricRuleEvaluationsPassed(new MetricOptions { Statistic = Statistic.SUM }) },
{ "ruleEvaluationsFailed", matchmakingRuleSet.Metric("ruleEvaluationsFailed") }
}
});
new Alarm(this, "Alarm", new AlarmProps {
Metric = ruleEvaluationRatio,
Threshold = 0.1,
EvaluationPeriods = 3
});
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var matchmakingRuleSet MatchmakingRuleSet
// Alarm that triggers when the per-second average of not placed matches exceed 10%
ruleEvaluationRatio := cloudwatch.NewMathExpression(&MathExpressionProps{
Expression: jsii.String("1 - (ruleEvaluationsPassed / ruleEvaluationsFailed)"),
UsingMetrics: map[string]IMetric{
"ruleEvaluationsPassed": matchmakingRuleSet.metricRuleEvaluationsPassed(&MetricOptions{
"statistic": cloudwatch.Statistic_SUM,
}),
"ruleEvaluationsFailed": matchmakingRuleSet.metric(jsii.String("ruleEvaluationsFailed")),
},
})
cloudwatch.NewAlarm(this, jsii.String("Alarm"), &AlarmProps{
Metric: ruleEvaluationRatio,
Threshold: jsii.Number(0.1),
EvaluationPeriods: jsii.Number(3),
})
Initializer
new MathExpression(props: MathExpressionProps)
MathExpression(props: MathExpressionProps)
new MathExpression(MathExpressionProps props)
new MathExpression(MathExpressionProps props)
NewMathExpression(Props MathExpressionProps)
Properties
colormay be undefinedstringcolormay be undefinedstrcolormay be undefinedStringColormay be undefinedstringColormay be undefined*string#labelmay be undefinedstringlabelmay be undefinedstrlabelmay be undefinedStringLabelmay be undefinedstringLabelmay be undefined*string#searchAccountmay be undefinedstringsearch_accountmay be undefinedstrsearchAccountmay be undefinedStringSearchAccountmay be undefinedstringSearchAccountmay be undefined*string#searchRegionmay be undefinedstringsearch_regionmay be undefinedstrsearchRegionmay be undefinedStringSearchRegionmay be undefinedstringSearchRegionmay be undefined*string#usingMetrics{ [key: string]: IMetric }using_metricstyping.Mapping[str, IMetric]usingMetricsMap<String, IMetric>UsingMetricsIDictionary<string, IMetric>UsingMetrics*map[string]IMetric#warningsmay be undefinedstring[]warningsmay be undefinedtyping.List[str]warningsmay be undefinedList<String>Warningsmay be undefinedstring[]Warningsmay be undefined*[]*stringdeprecated#warningsV2may be undefined{ [key: string]: string }warnings_v2may be undefinedtyping.Mapping[str, str]warningsV2may be undefinedMap<String, String>WarningsV2may be undefinedIDictionary<string, string>WarningsV2may be undefined*map[string]*string#Methods
createAlarm(scope: Construct, id: string, props: CreateAlarmOptions): Alarmdef create_alarm(self, scope: Construct, id: str, props: CreateAlarmOptions) -> Alarmpublic Alarm createAlarm(Construct scope, String id, CreateAlarmOptions props)public Alarm CreateAlarm(Construct scope, string id, CreateAlarmOptions props)func CreateAlarm(Scope Construct, Id *string, Props CreateAlarmOptions) Alarm#Combines both properties that may adjust the metric (aggregation) as well as alarm properties.
toMetricConfig(): MetricConfigdef to_metric_config(self, ) -> MetricConfigpublic MetricConfig toMetricConfig()public MetricConfig ToMetricConfig()func ToMetricConfig() MetricConfig#toString(): stringdef to_string(self, ) -> strpublic String toString()public string ToString()func ToString() *string#with(props: MathExpressionOptions): MathExpression // chainabledef with(self, props: MathExpressionOptions) -> MathExpressionpublic MathExpression with(MathExpressionOptions props)public MathExpression With(MathExpressionOptions props)func With(Props MathExpressionOptions) MathExpression#All properties except namespace and metricName can be changed.
1 parameter
Parameters
propspropspropspropsProps— The set of properties to change.