Splunk Search

eliminate some value in fields in stats count.

sandeepmakkena
Contributor
index=* 
| spath msg.uri 
| rename msg.uri as url
| rex field=url "shop(?<ex_url>[a-zA-Z\/\-0-9\.]+)" 
| rex field=ex_url "buy-(?<family>[^\/]+)\/(?<product>[^\/]+)" 
| eval url_N="/shop/"+"buy-"+family +"/" + product +"/"
| eval N_url = coalesce(url, url_N)
| stats count by N_url
| sort -count
| head 100

I am trying to find count by URL, but I also need to combine count value that looks like /shop/buy-phone/LG'. /shop/buy-laptop/Mac as /shop/buy-phone/ or /shop/buy-laptop/. Finally, when I count my URL I need to include these group URLs count with the other URL. I tried above, I am missing something.
Thanks for your time.

0 Karma

FrankVl
Ultra Champion

Do I understand correctly that you basically want a count per product (based on the unique url for that product) and a sum per product family? That could be done by doing something like below (including the family in the stats command you already had and then add an eventstats command to calculate the sum of counts by family.

index=* 
| spath msg.uri 
| rename msg.uri as url
| rex field=url "shop(?<ex_url>[a-zA-Z\/\-0-9\.]+)" 
| rex field=ex_url "buy-(?<family>[^\/]+)\/(?<product>[^\/]+)" 
| eval url_N="/shop/"+"buy-"+family +"/" + product +"/"
| eval N_url = coalesce(url, url_N)
| stats count by family,N_url
| eventstats sum(count) as familycount by family
| sort -count
| head 100

If that is not what you're after, please give an example of the expected output you're looking for.

0 Karma

sandeepmakkena
Contributor

Thanks for your response. What I'm looking for is different.
I want a stats count of URL, but I want to group count with this format /shop/buy-family/product/ as one and without that as a single URL.

Here is an example:

url field data:

/fr/shop/buy-phone/LG/v20-%0gsgwwguwfwrwwygswiswosubwbwi-nwsiwuhs/
/Ind/shop/buy-phone/LG/v30-%hxeuteiehiexhi/
/US/shop/buy-phone/Apple/iphone-4s
/ch/shop/buy-phone/LG/v60
/us/shop/buy-laptop/Mac/
/pk/shop/buy-laptop/Mac-pro/
/gr/shop/buy-laptop/Samsung/
/shop/browse/user/
/browse/user/laptop/ 

I want stats to be:

/shop/buy-phone/LG/  -   3
/shop/buy-phone/Apple/ - 1
 /shop/buy-laptop/Mac/ -1
/shop/buy-laptop/Mac-pro/ -1
/shop/buy-laptop/Samsung/ -1
/shop/browse/user/.     -  1
/browse/user/laptop/     - 1
0 Karma
Get Updates on the Splunk Community!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...