我正在尝试根据我拥有的不同端点来聚合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是一个通配符。有没有一种方法可以聚合这些通配符?
发布于 2019-10-25 15:21:20
有几种方法可以实现你所要求的。我认为最直接的建议是使用| 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)
https://stackoverflow.com/questions/58549347
复制相似问题