Sumologic 中的聚合通配符
Posted
技术标签:
【中文标题】Sumologic 中的聚合通配符【英文标题】:Aggregating Wildcards in Sumologic 【发布时间】:2019-10-24 21:28:15 【问题描述】:我正在尝试根据我拥有的不同端点聚合 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
问题在于,虽然我得到了 /v1/vehicle_locations
和 /v1/driver_locations
的正确聚合,但我得到了 /v1/driver_locations/id
和 /v1/vehicle_locations/id
的单独结果,因为 id 是通配符。有没有办法也可以聚合这些通配符?
【问题讨论】:
【参考方案1】:有几种方法可以实现您的要求。我认为最直接和建议的方法是使用 | parse
运算符,这样您就可以将路径的最顶层元素视为一个字段,例如
_sourceCategory=production
| keyvalue auto
| parse field=path "*/*" as topmost, rest
| where (topmost = "vehicle_locations" or topmost = "driver_locations")
| count by topmost
请注意,默认情况下 | parse
operator 适用于原始消息(例如原始日志行),但您可以使其解析字段 - 使用 field=
语法,这就是上面使用的内容。
您可能希望根据遇到的实际路径调整解析表达式或使用正则表达式。
(免责声明:我目前受雇于 Sumo Logic)
【讨论】:
以上是关于Sumologic 中的聚合通配符的主要内容,如果未能解决你的问题,请参考以下文章