CloudWatch 警报错误百分比 API 网关

Jai*_*e S 5 amazon-web-services aws-cloudformation amazon-cloudwatch terraform cloudwatch-alarms

我正在尝试使用 terraform 在 Cloudwatch 中设置和报警。我的警报基本上需要检查在 1 分钟的 2 个周期内网关中是否有超过 5% 的 5xx 错误。

我已经尝试了以下代码,但它不起作用:

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"
  }
}
Run Code Online (Sandbox Code Playgroud)

即使部署了警报,也不会显示数据。做一些测试时,我注意到该警报显然不接受单位“百分比”。

有没有人有一个例子terraform或cloudformation如何配置此类报警?

Jai*_*e S 5

根据Marcin评论中提供的信息,我在 aws 文档中找到了此信息:

Average 统计量表示 5XXError 错误率,即该时间段内 5XXError 错误总数除以请求总数。分母对应于 Count 指标(如下)。

我在 terraform 中配置的警报如下所示:

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"
  }
}
Run Code Online (Sandbox Code Playgroud)