You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何拆分AWS CloudWatch日志中的字典项并统计单个元素频次?

AWS CloudWatch日志多条目拆分统计解决方案

针对你遇到的日志解析问题,只需在原有查询基础上增加字符串拆分、行展开和格式清理步骤,即可实现单个条目的独立计数:

filter @message like /ERROR/
| parse "message1 {*}" as raw_types
| split(raw_types, ", ") as type_array
| mv_expand type_array
| parse type_array "'*'" as cleaned_type
| stats count() as count by cleaned_type

各步骤说明:

  • 拆分字符串为数组:split(raw_types, ", ") as type_array 将原始的多条目字符串(如'A', 'B', 'C')按, 分割成数组,每个元素对应一个独立条目。
  • 展开数组为单行:mv_expand type_array 把数组中的每个元素单独拆分成一行日志,让原来一条日志里的多个条目变成多条单条目日志。
  • 清理条目格式:parse type_array "'*'" as cleaned_type 去掉条目的单引号,得到干净的条目名称(如A、B)。
  • 统计单个条目计数:最后通过stats按清理后的条目分组计数,就能得到你期望的结果。

执行后输出示例:

cleaned_type  count
A             4
B             2
C             1

内容的提问来源于stack exchange,提问作者Hardik Gupta

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.23 06:48:19