在 Amazon Cloudwatch Insights 中,您如何对统计数据进行统计?

In Amazon Cloudwatch Insights, how do you take a statistic of a statistic?

我正在使用 AWS Cloudwatch Insights 和 运行 这样的查询:

fields @message, @timestamp
| filter strcontains(@message, "Something of interest happened")
| stats count() as interestCount by bin(10m) as tenMinuteTime
| stats max(interestCount) by datefloor(tenMinuteTime, 1d)

但是,在最后一行,我收到以下错误:

mismatched input 'stats' expecting {K_PARSE, K_SEARCH, K_FIELDS, K_DISPLAY, K_FILTER, K_SORT, K_ORDER, K_HEAD, K_LIMIT, K_TAIL}

这似乎意味着我无法在Insights中进行多层统计查询,因此无法进行统计的统计。有解决办法吗?

您目前不能使用多个 stat 命令,据我所知,目前没有直接的解决方法。但是,您可以加厚单个 stat 命令并用逗号分隔,如下所示:

fields @message, @timestamp
| filter strcontains(@message, "Something of interest happened")
| stats count() as @interestCount, 
max(interestCount) as @maxInterest, 
interestCount by bin(10m) as @tenMinuteTime

您在 stats 之后定义字段并使用函数,然后处理这些结果字段。