在 AWS Log Insights 图表中将空箱显示为零值

pba*_*pba 9 amazon-cloudwatch aws-cloudwatch-log-insights

通过 bin 进行计数查询:

filter @message like / error /
| stats count() as exceptionCount by bin(30m)
Run Code Online (Sandbox Code Playgroud)

我得到一个不连续的图,很难掌握:

图形

AWS Cloudwatch Log Insights 是否可以将空箱视为零计数以获得连续图形?

Joe*_*esh 12

发现你的问题正在寻找我自己的答案。

我想出的最好办法是计算“存在”字段,然后使用 sum 来获取时间仓中的 0。

我使用了 strcontains,匹配时返回 1,不匹配时返回 0。https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/CWL_QuerySyntax.html#CWL_QuerySyntax-operations-functions

我的看起来像这样:

fields @timestamp, @message
| fields strcontains(@message, 'Exit status 1') as is_exit_message
| stats sum(is_exit_message) as is_exit_message_count by bin(15m) as time_of_crash
| sort time_of_crash desc
Run Code Online (Sandbox Code Playgroud)

所以,你的将是:

fields strcontains(@message, 'error') as is_error
| stats sum(is_error) as exceptionCount by bin(30m)
Run Code Online (Sandbox Code Playgroud)

  • 这种方法是有效的,除非如果日志消息没有匹配的字符串,您仍然只能得到零。如果在 bin 周期内根本没有日志消息(在我的例子中是大多数 bin),它仍然是不连续的 (6认同)