我正在尝试根据我拥有的不同端点来汇总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
的正确汇总,但是由于id是通配符,所以我得到了/v1/driver_locations/id
和/v1/vehicle_locations/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=
语法使其解析字段。
您可能要调整解析表达式或使用正则表达式,具体取决于遇到的实际路径。
(Disclamer:我目前在Sumo Logic工作)