View a markdown version of this page

针对每个端点的高延迟创建日志警报 - Amazon CloudWatch
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)。

针对每个端点的高延迟创建日志警报

您可以创建一个多贡献者日志警报来监控按端点分组的平均延迟。如果任何端点超过延迟阈值,则警报将转换为 ALARM 状态。

以下示例创建了一个日志警报,当任何端点在 5 次查询执行中有 3 次的平均延迟超过 1000 毫秒时,该警报将进入 ALARM 状态。

aws cloudwatch put-log-alarm \ --alarm-name "EndpointLatency" \ --alarm-description "Alarm when any endpoint latency exceeds 1000ms" \ --comparison-operator GreaterThanThreshold \ --threshold 1000 \ --query-results-to-evaluate 5 \ --query-results-to-alarm 3 \ --treat-missing-data missing \ --alarm-actions "arn:aws:sns:region:account-id:topic-name" \ --scheduled-query-configuration '{ "QueryString": "parse @message /endpoint=(?<endpoint>\\S+).*latency=(?<latency>\\d+)/", "LogGroupIdentifiers": ["/aws/apigateway/my-api"], "ScheduledQueryRoleARN": "arn:aws:iam::account-id:role/ScheduledQueryRole", "AggregationExpression": "avg(latency) by endpoint", "ScheduleConfiguration": { "ScheduleExpression": "rate(5 minutes)", "StartTimeOffset": 300 } }'

在此示例中,endpoint 的每个唯一值都成为贡献者。如果任何贡献者的平均延迟超过 1000 毫秒,则警报将转换为 ALARM 状态并发送通知,指出哪个端点违规。