最近, AWS宣布Cloudwatch警报可以对指标使用数学表达式。我决定创建一个警报,以比较2个单一指标的总和与给定阈值。这意味着根据AWS文档,我的表达式应为SUM([m1,m2]),其中m1和m2是2个单一指标。我还决定使用cloudformation模板(在yaml中)实现这个想法。这是Cloudwatch警报定义:
BillingAlarmExpression:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmActions:
- !Ref BillingAlertTopic
AlarmDescription: String
ComparisonOperator: GreaterThanOrEqualToThreshold
EvaluationPeriods: 1
Metrics:
- Id: m1
MetricStat:
Metric:
Dimensions:
- Name: ServiceName
Value: AmazonEC2
- Name: Currency
Value: USD
MetricName: EstimatedCharges
Namespace: AWS/Billing
Period: 86400
Stat: Maximum
ReturnData: False
- Id: m2
MetricStat:
Metric:
Dimensions:
- Name: ServiceName
Value: AmazonCloudwatch
- Name: Currency
Value: USD
MetricName: EstimatedCharges
Namespace: AWS/Billing
Period: 86400
Stat: Maximum
ReturnData: False
- Id: Expr1
Expression: SUM([m1,m2])
Label: Yeap
Threshold: 100 …Run Code Online (Sandbox Code Playgroud)