amazon-web-services - AWS CloudWatch Logs Insight 查询以使用 ALB 日志找出服务可用性
问题描述
我在我的 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 查询来实现这一点?
解决方案
推荐阅读
- c++ - 我可以使用 unique_lock 锁定互斥锁并安全地返回变量吗?我必须先复制它吗?
- java - 错误:无法找到或加载主类 org.apache.maven.wrapper.MavenWrapperMain
- python - 使用 Docker 卷使用 VSCode 调试 Docker 容器内的 Django 后端
- data-structures - 为什么树搜索比图搜索更昂贵?
- sql - 合并来自不同表的两个不同字段的 MS Access SQL 查询显示参考 ID 而不是实际值
- django - ImportError:没有名为skeleton.settings的模块
- c# - 实体框架查询中不区分大小写的字符串比较
- sbt - 是否可以在不禁用 sbt 中的 publishLocal 的情况下禁用发布?
- animation - 滚动视图中元素的 SwiftUI 动画不起作用?Xcode GM 更新
- reactjs - 我想将主要反应应用程序的路由拆分为多个包。怎么做?