CloudWatch 警报错误百分比 API 网关
CloudWatch Alarm Percentage of errors API Gateway
我正在尝试使用 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"
}
}
即使部署了警报,也不会显示数据。
做一些测试我注意到显然这个警报不接受单位“百分比”。
terraform
或 cloudformation
中是否有人提供有关如何配置此类警报的示例?
我在 CloudFormation 上使用它并且工作正常,我使用 SUM 而不是“百分比”
ApiGateway5XXErrorAlarm:
Type: 'AWS::CloudWatch::Alarm'
Properties:
AlarmDescription: 'Api Gateway server-side errors captured'
Namespace: 'AWS/ApiGateway'
MetricName: 5XXError
Dimensions:
- Name: ApiName
Value: !Ref ApiGateway
- Name: Stage
Value: dev
Statistic: Sum
Period: 60
EvaluationPeriods: 1
Threshold: 1
ComparisonOperator: GreaterThanOrEqualToThreshold
AlarmActions:
- !Ref Alerts
TreatMissingData: notBreaching
根据 aws 文档中 Marcin, I've found this info 的评论中提供的信息:
The Average statistic represents the 5XXError error rate, namely, the total count of the 5XXError errors divided by the total number of requests during the period. The denominator corresponds to the Count metric (below).
我在 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"
}
}
我正在尝试使用 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"
}
}
即使部署了警报,也不会显示数据。 做一些测试我注意到显然这个警报不接受单位“百分比”。
terraform
或 cloudformation
中是否有人提供有关如何配置此类警报的示例?
我在 CloudFormation 上使用它并且工作正常,我使用 SUM 而不是“百分比”
ApiGateway5XXErrorAlarm:
Type: 'AWS::CloudWatch::Alarm'
Properties:
AlarmDescription: 'Api Gateway server-side errors captured'
Namespace: 'AWS/ApiGateway'
MetricName: 5XXError
Dimensions:
- Name: ApiName
Value: !Ref ApiGateway
- Name: Stage
Value: dev
Statistic: Sum
Period: 60
EvaluationPeriods: 1
Threshold: 1
ComparisonOperator: GreaterThanOrEqualToThreshold
AlarmActions:
- !Ref Alerts
TreatMissingData: notBreaching
根据 aws 文档中 Marcin, I've found this info 的评论中提供的信息:
The Average statistic represents the 5XXError error rate, namely, the total count of the 5XXError errors divided by the total number of requests during the period. The denominator corresponds to the Count metric (below).
我在 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"
}
}