amazon-cloudwatch - 访问 JSON 数组中的值
问题描述
我正在按照文档中关于如何访问 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
}]
解决方案
您发布的参考链接还说明了以下内容。
CloudWatch Logs Insights 最多可以从 JSON 日志中提取 100 个日志事件字段。对于未提取的额外字段,您可以使用 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
推荐阅读
- javascript - 是否有可能有多个未完成的异步请求?
- ibm-watson - 将 DNN 模型发送到 Watson 进行训练时打开数据文件时出错
- c# - 这个 Ajax 调用有什么问题?
- python - 使用 Anaconda 导入 Keras 时出现 ImportError
- google-cloud-platform - 在本机模式下禁用 Firestore
- python - 有没有办法在 Scrapy 中搜索关键字
- mysql - Django 迁移错误 1064
- asp.net - 从 HttpModule 中的数据库获取角色
- java - 为什么会出现这个 gradle 错误?建设项目的时候?
- apache - 如何配置 Apache 代理以正确返回 JAX-WS WSDL XSD 位置