【问题标题】:Count Array Length in JSON Message Object with Amazon Cloudwatch Logs Insights使用 Amazon Cloudwatch Logs Insights 计算 JSON 消息对象中的数组长度
【发布时间】:2019-10-09 21:24:53
【问题描述】:

有什么方法可以获取在云观察日志洞察解析的 JSON 对象中找到的数组的长度?

例如,发送以下结构的 JSON 对象以记录见解时:

{
  names: ['john', 'doe', 'joe', 'schmoe']
}

它被解析为以下字段:

  names.0: john
  names.1: doe
  names.2: joe
  names.3: schmoe

并且可以通过

访问
fields @timestamp, names.0, names.1, ...

在这个例子中,有没有办法得到一个名为number_of_namesfield

  • 例如,| parse get_length(names) as number_of_names

【问题讨论】:

  • 知道怎么做吗?
  • 我还没有找到方法 - 求助于从我的应用程序中发出“计数”

标签: json amazon-web-services amazon-cloudwatch aws-cloudwatch-log-insights


【解决方案1】:

对于已知最大长度的较小数组,这是一个丑陋的解决方法:

fields @timestamp, ispresent(names.0) + ispresent(names.1) + ispresent(names.2) + ... + ispresent(names.10) as names_length

【讨论】:

  • 不幸的是一个有效的答案! (畏缩)
猜你喜欢
  • 2021-11-11
  • 2021-12-01
  • 2020-11-20
  • 1970-01-01
  • 2021-07-04
  • 1970-01-01
  • 1970-01-01
  • 2022-09-28
  • 1970-01-01
相关资源
最近更新 更多