Cloudwatch 见解,按 JSON 个值的值查询图表?

Cloudwatch insights, query to graph by value of JSON values?

我的日志中有一个 JSON 对象,如下所示:

"result":{
   "totalRecords":8,
   "bot":3,
   "member":5,
   "message":0,
   "reaction":0,
   "success":0,
   "error":0,
   "unknown":8
}

我正在尝试编写一个日志洞察查询来绘制每个键的值。本质上,我想要一个折线图,每个键的值都有不同的线。目前我的查询如下:

fields result.bot, result.error, result.member, result.message, result.reaction, 
result.success, result.totalRecords, result.unknown
| stats count(result.bot), count(result.error), 
 count(result.member),count(result.message),
 count(result.reaction),count(result.success),
 count(result.totalRecords), count(result.unknown) by bin(30s)

这 return 是键在日志中出现的次数,而不是值。

我需要知道的是您使用什么来获取给定键的值。我尝试按照 AWS 文档中的建议附加 .0,例如 count(result.totalRecords.0),但它没有 return 任何值。什么是键值查询?

基于文档

Counts the log events. count() (or count(*)) counts all events returned by the query, while count(fieldName) counts all records that include the specified field name.

你可以改写

stats sum(result.bot), sum(result.error) by bin (30s)

等这将为您提供 30 秒内这些值的总和。如果您想要更大的粒度,可以缩短周期。