amazon-web-services - 如何将 CloudWatch 警报配置为每 X 分钟评估一次
问题描述
我想将 CloudWatch 警报配置为:
- 每 30 分钟对 ApplicationRequestsTotal 指标的最后 30 分钟求和一次
- 如果总和等于 0 则报警
我已将自定义 CloudWatch ApplicationRequestsTotal 指标配置为每 60 秒为我的服务发出一次。
我已将警报配置为:
{
"MetricAlarms": [
{
"AlarmName": "radio-silence-alarm",
"AlarmDescription": "Alarm if 0 or less requests are received for 1 consecutive period(s) of 30 minutes.",
"ActionsEnabled": true,
"OKActions": [],
"InsufficientDataActions": [],
"MetricName": "ApplicationRequestsTotal",
"Namespace": "AWS/ElasticBeanstalk",
"Statistic": "Sum",
"Dimensions": [
{
"Name": "EnvironmentName",
"Value": "service-environment"
}
],
"Period": 1800,
"EvaluationPeriods": 1,
"Threshold": 0.0,
"ComparisonOperator": "LessThanOrEqualToThreshold",
"TreatMissingData": "missing"
}
],
"CompositeAlarms": []
}
我已经设置了许多这样的警报,每个警报似乎都是:
- 每分钟对 ApplicationRequestsTotal 指标的最后 30 分钟求和一次
例如,该服务在上午 8:36 开始获得 0 ApplicationRequestsTotal,并在上午 9:06 CloudWatch 触发了警报。
上述时间段的 aws cloudwatch describe-alarm-history:
{
"AlarmName": "radio-silence-alarm",
"AlarmType": "MetricAlarm",
"Timestamp": "2021-09-29T09:06:37.929000+00:00",
"HistoryItemType": "StateUpdate",
"HistorySummary": "Alarm updated from OK to ALARM",
"HistoryData": "{
"version":"1.0",
"oldState":{
"stateValue":"OK",
"stateReason":"Threshold Crossed: 1 datapoint [42.0 (22/09/21 08:17:00)] was not less than or equal to the threshold (0.0).",
"stateReasonData":{
"version":"1.0",
"queryDate":"2021-09-22T08:47:37.930+0000",
"startDate":"2021-09-22T08:17:00.000+0000",
"statistic":"Sum",
"period":1800,
"recentDatapoints":[
42.0
],
"threshold":0.0,
"evaluatedDatapoints":[
{
"timestamp":"2021-09-22T08:17:00.000+0000",
"sampleCount":30.0,
"value":42.0
}
]
}
},
"newState":{
"stateValue":"ALARM",
"stateReason":"Threshold Crossed: 1 datapoint [0.0 (29/09/21 08:36:00)] was less than or equal to the threshold (0.0).",
"stateReasonData":{
"version":"1.0",
"queryDate":"2021-09-29T09:06:37.926+0000",
"startDate":"2021-09-29T08:36:00.000+0000",
"statistic":"Sum",
"period":1800,
"recentDatapoints":[
0.0
],
"threshold":0.0,
"evaluatedDatapoints":[
{
"timestamp":"2021-09-29T08:36:00.000+0000",
"sampleCount":30.0,
"value":0.0
}
]
}
}
}"
}
我有什么配置不正确?
解决方案
这不是 Amazon CloudWatch 的工作方式。
在 CloudWatch 中创建警报时,您指定:
- 指标(例如 CPU 利用率,或者可能是发送到 CloudWatch 的自定义指标)
- 一个时间段(例如前 30 分钟)
- 一种聚合方法(例如,Average、Sum、Count)
例如,如果在过去 30 分钟内超过了指标的平均值,CloudWatch 可以触发警报。这被持续评估为一个滑动窗口。它不查看不同的 30 分钟块中的指标。
使用您的示例,只要指标总和在前30 分钟内为零,它就会连续发送警报。
推荐阅读
- javascript - Google App Script未以所需格式打印列表项
- angular - 如何使用角度在 ts 文件中发送表单数据?
- reactjs - 我可以在 Context API 中使用 React Context API 还是必须合并它们?
- flutter - 如何将 Flutter App 中的图像上传到我的服务器并解码来自服务器的 json 响应?
- git - 在一个项目中同步两个存储库 + Sourcetree
- python - 如何更有效地根据先前列 y 中的值计算列 y+1(蒙特卡洛模拟)
- azure - Azure IoT 中心并使用 mosquitto_pub 发送消息
- reactjs - 如何在 React 中实现输入自动选项卡(关注 keyup 事件的下一个输入元素)?
- kubernetes - 在全局启用 istio 和 mTLS 的情况下公开虚拟服务
- php - 在 PHP 递归函数中,如何检查它是最后一次迭代?