AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 1025972
Accepted
Michael Oryl
Michael Oryl
Asked: 2020-07-21 06:16:03 +0800 CST2020-07-21 06:16:03 +0800 CST 2020-07-21 06:16:03 +0800 CST

CloudWatch InSights:如何以列表的形式一次提取/查询所有 JSON 数组元素

  • 772

我的公司已开始使用 JSON 日志记录,以便更好地支持 AWS 上的 CloudWatch InSights 查询。查询很容易使用,除非我们处理数组数据。

例如,如果我们有如下日志条目:

{
  "id": 123,
  "method": "getRelatedPolicies",
  "policiesRetrieved": [
    "333g",
    "444q"
  ]
}
{
  "id": 222,
  "method": "getRelatedPolicies",
  "policiesRetrieved": [
    "123q",
    "234w",
    "345e",
    "456r"
  ]
}
{
  "id": 432,
  "method": "getRelatedPolicies",
  "policiesRetrieved": [
    "345e"
  ]
}

它们在 CloudWatch Insights 中变平,如下所示:

  id                    123,
  method                getRelatedPolicies
  policiesRetrieved.0   333g
  policiesRetrieved.1   444q


  id                    222,
  method                getRelatedPolicies
  policiesRetrieved.0   123q
  policiesRetrieved.1   234w
  policiesRetrieved.2   345e
  policiesRetrieved.3   456r


  id                    432,
  method                getRelatedPolicies
  policiesRetrieved.0   345e

但是我能做些什么来搜索 policyRetrieved 数组包含值的任何日志条目345e?数组中可能有任意数量的条目,所以我不能只是开始添加过滤器行,如or policiesRetrieved.0 = "345e" or policiesRetrieved.1 = "345e"....

如果我可以将所有值折叠成一个分隔字符串,那么我可以在字符串 PLUS 中搜索匹配项,如果用户将数据导出为 CSV 或其他一些非 AWS 格式以便进一步使用,我也可以轻松地使用该列表分析。

我可以以某种方式将数组值解析为字符串吗?我查看了查询中所有可用的辅助函数,但没有什么让我觉得可行。

任何解决方案将不胜感激。

amazon-web-services amazon-cloudwatch
  • 1 1 个回答
  • 11209 Views

1 个回答

  • Voted
  1. Best Answer
    Michael Oryl
    2020-07-22T04:50:19+08:002020-07-22T04:50:19+08:00

    所以我的特殊情况的解决方案很简单,因为有问题的数组只包含字符串。[我只是将and中的数组内容解析]为单个字符串。这适用于字符串或数字或布尔值的数组。如果我想提取对象数组的 ID,那就不那么漂亮了。

    无论如何,这是一个解析数组中字符串的示例查询:

    fields @timestamp, id, method # you don't need to put the 'policyNumbers' up here - it is added automatically
    | parse @message '"policyNumbers":[*]' as policyNumbers
    #| filter policyNumbers like '234w' # Uncomment to show only entries that mention a specific policy
    

    这将解析以下行:

    {"timestamp":"2020-07-21T12:03:46.970Z","id":222,"method": "getRelatedPolicies","dataAccess":{"policyNumbers":["123q", "234w", "345e", "456r"]}}}
    

    id存在222,method存在getRelatedPolicies, 并具有policyNumbers价值"123q", "234w", "345e", "456r"

    • 3

相关问题

  • 与 AWS 中的其他系统相比,CentOS 报告的总内存较低

  • 如何在 Amazon Linux 服务器上升级到 Java 1.8?

  • 了解 Amazon AWS 使用数据

  • 亚马逊提供的负载均衡服务体验如何?

  • ELB 中现有节点的 AWS 自动缩放问题

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve