【问题标题】:Display empty bin as a zero value in AWS Log Insights graph在 AWS Log Insights 图表中将空 bin 显示为零值
【发布时间】:2020-09-28 16:16:53
【问题描述】:

通过 bin 进行此计数查询:

filter @message like / error /
| stats count() as exceptionCount by bin(30m)

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

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

【问题讨论】:

    标签: amazon-cloudwatch aws-cloudwatch-log-insights


    【解决方案1】:

    找到您的问题,寻找我自己的答案。

    我想出的最好办法是计算一个“存在”字段,然后使用 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
    

    所以,你会是:

    fields strcontains(@message, 'error') as is_error
    | stats sum(is_error) as exceptionCount by bin(30m)
    

    【讨论】:

    • 我的原始请求实际上是使用正则表达式:filter @message like /Request [0-9]* (exception|error)/ | stats count(*) as exceptionCount by bin(30m)。在我的具体情况下,我设法通过使用 filter @message like /Request [0-9]*/ | fields strcontains(@message, 'exception') + strcontains(@message, 'error') as is_error | stats sum(is_error) as exceptionCount by bin(30m) 来使用你的 strcontains 技巧
    • 这种方法有效,但如果有没有匹配字符串的日志消息,您仍然只会得到零。如果在 bin 期间根本没有日志消息(在我的情况下是大多数 bin),它仍然是不连续的
    • 是的,我同意@user1169420,如果那段时间没有日志消息,它仍然显示折扣。有什么解决方法吗?
    【解决方案2】:

    使用strcontains + sumparse + count

    重点不是使用filter。您应该查询所有日志。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-10
      • 2020-12-22
      • 2021-04-08
      • 2021-09-17
      相关资源
      最近更新 更多