CloudWatch警报错误百分比API网关 [英] CloudWatch Alarm Percentage of errors API Gateway
问题描述
我正在尝试使用Terraform在Cloudwatch中进行设置并发出警报. 我的警报基本上需要检查在2分钟的1分钟内网关中是否存在5%以上的5xx错误.
I'm trying to setup and alarm in Cloudwatch using terraform. My alarm basically needs to check if there is more than 5% of 5xx errors in the gateway during 2 periods of 1 minute.
我尝试了以下代码,但无法正常工作:
I've tried the following code but it's not working:
resource "aws_cloudwatch_metric_alarm" "gateway_error_rate" {
alarm_name = "gateway-errors"
comparison_operator = "GreaterThanOrEqualToThreshold"
alarm_description = "Gateway error rate has exceeded 5%"
treat_missing_data = "notBreaching"
metric_name = "5XXError"
namespace = "AWS/ApiGateway"
period = 60
evaluation_periods = 2
threshold = 5
statistic = "Average"
unit = "Percent"
dimensions = {
ApiName = "my-api"
Stage = "dev"
}
}
即使部署了警报,也不会显示数据. 在进行一些测试时,我已经注意到,显然单位百分率"是单位百分数".不会被此警报接受.
Even thee alert is deployed, the data is not displayed. Doing some tests I've noticed that apparently the unit "percent" is not accepted for this alarm.
有人在terraform
或cloudformation
中有一个示例,说明如何配置这种类型的警报吗?
Does anyone have an example in terraform
or cloudformation
on how to configure this type of alarms?
推荐答案
Based on the information provided in the comments by Marcin, I've found this info in the aws documentation:
平均值统计量表示5XXError错误率,即5XXError错误的总数除以该期间的请求总数.分母对应于计数"度量标准(如下).
我在Terraform中配置的警报如下:
My alarm configured in terraform looks as follow:
resource "aws_cloudwatch_metric_alarm" "gateway_error_rate" {
alarm_name = "gateway-errors"
comparison_operator = "GreaterThanOrEqualToThreshold"
alarm_description = "Gateway error rate has exceeded 5%"
treat_missing_data = "notBreaching"
metric_name = "5XXError"
namespace = "AWS/ApiGateway"
period = 60
evaluation_periods = 2
threshold = 0.05
statistic = "Average"
unit = "Count"
dimensions = {
ApiName = "my-api"
Stage = "dev"
}
}
这篇关于CloudWatch警报错误百分比API网关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!