aggregate - Sumologic 中的聚合通配符
问题描述
我正在尝试根据我拥有的不同端点聚合 API 日志。一共有4个端点:
1:/v1/vehicle_locations
2:/v1/vehicle_locations/id
3:/v1/driver_locations
4:/v1/driver_locations/id
我目前这样做的方式是:
_sourceCategory=production | keyvalue auto | where (path matches "/v1/driver_locations" OR path matches "/v1/driver_locations/*" or path matches "/v1/vehicle_locations" or path matches "/v1/vehicle_locations/*") | count by path
问题在于,虽然我得到了 and 的正确聚合,但我得到了/v1/vehicle_locations
and的/v1/driver_locations
单独结果/v1/driver_locations/id
,/v1/vehicle_locations/id
因为 id 是通配符。有没有办法我也可以聚合这些通配符?
解决方案
有几种方法可以实现您的要求。我认为最直接和建议的方法是使用| parse
运算符,以便您可以将路径的最顶层元素视为一个字段,例如
_sourceCategory=production
| keyvalue auto
| parse field=path "*/*" as topmost, rest
| where (topmost = "vehicle_locations" or topmost = "driver_locations")
| count by topmost
请注意,默认情况下,| parse
运算符适用于原始消息(例如原始日志行),但您可以使其解析字段 - 使用field=
语法,这就是上面使用的。
您可能需要根据遇到的实际路径调整解析表达式或使用正则表达式。
(免责声明:我目前受雇于 Sumo Logic)
推荐阅读
- java - 使用 Java 将 JSON 转换为 POJO 并赋值
- go - gorm 与 foreignKey 参考有很多关系
- docker - 在 Docker 容器下的 GStreamer 管道之间共享内存
- python - 维度不匹配的数量 - Tensorflow
- typescript - 如何调用从父类继承的异步函数?
- python - 获取 FileNotFoundError:[Errno 2] 没有这样的文件或目录:(PYTHON)
- magento - Magento 2 WYSIWYG 编辑器按钮不起作用
- microsoft-graph-api - 使用 Microsoft Graph API 从术语库中弃用术语
- javascript - Javascript:向 Markdown 添加动态文本
- r - 编写在两个数据帧中发现差异的 R 函数