2

我在我的 ALB 上启用了访问日志,这些日志已发布到 AWS CloudWatch。我们有一个 ServiceHealth 检查端点,如果服务运行正常,它会返回 200。如果任何组件的行为不符合预期,它将返回 503 HTTP 响应代码。可能存在其他情况,例如 ALB 返回 5XX 状态的服务不可用。

我设法编写了 CloudWatch Logs 洞察查询,它为我提供了每个 HTTP 响应代码的计数。

fields @message
| parse @message "* * * *:* * * * * * * * * * * * *" as type, time, elb, client, port, target_port, request_processing_time, target_processing_time, response_processing_time, elb_status_code, target_status_code, received_bytes, sent_bytes, protocol, url, rest_of_the_message
| filter (strcontains(url, "ServiceHealth.php") and (elb_status_code = 200 or elb_status_code = 502 or elb_status_code = 503)
| stats count(*) by elb_status_code, elb_status_code

这将结果输出为:

电流输出

我希望结果以百分比的形式显示,计算如下:

Service Availability = (Number of responses with 200 Status Code/ (Total number of calls with 200 + 5XX Status Code)) * 100

Service Unvailability = (Number of responses with 5XX Status Code / (Total number of calls with 200 + 5XX Status Code)) * 100

是否可以使用 Logs Insights 查询来实现这一点?

4

0 回答 0