我正在尝试为 API 网关设置 Cloudwatch 警报。在此示例中,我尝试使用现有的 4xx 指标,但即使 4xx 指标显示数据点,警报也永远不会触发。我正在努力寻找自己做错了什么。此时我只想在出现任何 4xx 错误(例如 404)时立即触发警报。
这就是地形。我怀疑尺寸有误,但我不确定。预先感谢!
resource "aws_cloudwatch_metric_alarm" "gateway_error_rate" {
alarm_name = "${local.workspace_name}-gateway-errors"
comparison_operator = "GreaterThanOrEqualToThreshold"
alarm_description = "Gateway error rate has exceeded threshold"
treat_missing_data = "missing"
metric_name = "4xx"
namespace = "AWS/ApiGateway"
period = 60
evaluation_periods = 1
threshold = 1
statistic = "Sum"
unit = "Count"
dimensions = {
ApiName = aws_apigatewayv2_api.my_gateway.name
Stage = aws_apigatewayv2_stage.default.name
}
}
我就在不远的地方。最终的地形将尺寸从
ApiName
更改为 ApiId
,并将 unit
替换为 datapoints_to_alarm
resource "aws_cloudwatch_metric_alarm" "gateway_error_rate" {
alarm_name = "${local.workspace_name}-gateway-errors"
comparison_operator = "GreaterThanOrEqualToThreshold"
alarm_description = "Gateway error rate has exceeded threshold"
treat_missing_data = "missing"
metric_name = "4xx"
namespace = "AWS/ApiGateway"
period = 60
evaluation_periods = 1
threshold = 1
statistic = "Sum"
datapoints_to_alarm = 1
dimensions = {
ApiId = aws_apigatewayv2_api.my_gateway.id
Stage = aws_apigatewayv2_stage.default.name
}
}