首页 > 解决方案 > 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_locationsand的/v1/driver_locations单独结果/v1/driver_locations/id/v1/vehicle_locations/id因为 id 是通配符。有没有办法我也可以聚合这些通配符?

标签: aggregatesumologic

解决方案


有几种方法可以实现您的要求。我认为最直接和建议的方法是使用| 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)


推荐阅读