Splunk Search

regex for uri ignoring query params and path params.

donB
Loves-to-Learn Lots

I am trying to find the top api url's that were consumed by our clients. Our uri in logs are of below format.

1. https://api.server.com/user/1                       (type 1)
2. https://api.server.com/user/2                       (type 1)
3. https://api.server.com/user/3/role/1        (type 2)
4 . https://api.server.com/user?name=test  (type 3)

Now i need result count for each uri like below.

/user/{id} - 2

/user/{id}/role{id}. - 1

/user   - 1  (or user {filter} for query params e.g. /user/{filter})

i have unlimited combinations of such path parameters for different resources. what is the best way to get the count of url hits.

 

 

Labels (4)
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Without the full log entry or an example of the fields already extracted, I will have to guess that the url is either enclosed in double quotes or there is a trailing space of some kind and that the ids are all a series of digits

| rex "(?P<uri>https:\/\/api\.server\.com\/[^\?\"\s]+)"
| rex field=uri mode=sed max_match=0 "s/\/[\d]+/\/\{id\}/"
| stats count by uri

 

0 Karma
Get Updates on the Splunk Community!

Earn a $35 Gift Card for Answering our Splunk Admins & App Developer Survey

Survey for Splunk Admins and App Developers is open now! | Earn a $35 gift card!      Hello there,  Splunk ...

Continuing Innovation & New Integrations Unlock Full Stack Observability For Your ...

You’ve probably heard the latest about AppDynamics joining the Splunk Observability portfolio, deepening our ...

Monitoring Amazon Elastic Kubernetes Service (EKS)

As we’ve seen, integrating Kubernetes environments with Splunk Observability Cloud is a quick and easy way to ...