我正在遵循文档中有关如何在CloudWatch Insights中访问JSON值的说明,建议如下
JSON arrays are flattened into a list of field names and values. For example, to specify the value of instanceId for the first item in requestParameters.instancesSet, use requestParameters.instancesSet.items.0.instanceId.
参考 https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/CWL_AnalyzeLogData-discoverable-fields.html
我正在尝试以下操作,但没有得到任何回报。智能感知最多可自动填充processList.0
,但不会再填充
fields processList.0.vss
| sort @timestamp desc
| limit 1
我要使用的JSON是
"processList": [
{
"vss": xxxxx,
"name": "aurora",
"tgid": xxxx,
"vmlimit": "unlimited",
"parentID": 1,
"memoryUsedPc": 16.01,
"cpuUsedPc": 0.01,
"id": xxxxx,
"rss": xxxxx
},
{
"vss": xxxx,
"name": "aurora",
"tgid": xxxxxx,
"vmlimit": "unlimited",
"parentID": 1,
"memoryUsedPc": 16.01,
"cpuUsedPc": 0.06,
"id": xxxxx,
"rss": xxxxx
}]
答案 0 :(得分:0)
您尝试过以下吗?
fields @@timestamp, @processList.0.vss
| sort @@timestamp desc
| limit 5
可能是语法错误。如果没有,请发布一些有关整个结构的记录,包括@timestamp。
答案 1 :(得分:0)
您发布的参考链接还指出以下内容。
CloudWatch Logs Insights最多可以提取100个日志事件字段 从JSON日志中。对于未提取的其他字段,可以使用 parse命令从原始未解析的日志中解析这些字段 消息字段中的事件。
https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/CWL_AnalyzeLogData-discoverable-fields.html
对于非常大的JSON消息,Insights intellisense可能未将所有字段解析为命名字段。因此,解决方案是对您希望数据字段存在的字段中的完整JSON字符串使用parse。在您的示例中,它是 processList 。
通过使用如下查询,我能够在processList下提取特定cpuUsedPc的值。
fields @timestamp, cpuUtilization.total, processList
| parse processList /"name":"RDS processes","tgid":.*?,"parentID":.*?,"memoryUsedPc":.*?,"cpuUsedPc":(?<RDSProcessesCPUUsedPc>.*?),/
| sort @timestamp asc
| display @timestamp, cpuUtilization.total, RDSProcessesCPUUsedPc