Splunk Search

Grouping HTTP GET requests based on first directory

JaredYong
Explorer

Very new to splunk here. I would like to group each http request to each directory based on their directory, and produce a count for each and plot it in a pie chart.

GET /vendor, GET /Services, GET /config, GET /About

For example GET /vendor/vendor/auth/signin  and GET /vendor/vendor/browse should be classified under /vendor in a table.

my current query is wrong and doesn't show anything, modified it based on a GIAC paper.


index="apache_logs" | stats count by request | eval request=case(
request="GET /config*", "/config",
request="GET /vendor*", "/vendor",
request="GET /Services*", "/Services",
request="GET /About*", "/About")
request="GET /about*", "/about")
| top request limit=0 useother=f
| eval request=request." (".count." events, ".round(percent,2)."%)"

I would also like to differentiate requests to /about and /About 
 I hope this made sense. 

Labels (2)
0 Karma
1 Solution

venkatasri
SplunkTrust
SplunkTrust

Hi @JaredYong 

Can't give you a final query, however you can try using the combination of field extraction of /directory/ and stats it.

Example:

<your_base_query> "GET"
| rex field=request "\/(?<dir>\w+)\/" 
| stats count by dir

--

An upvote would be appreciated if this reply helps!

 

View solution in original post

Tags (1)

ITWhisperer
SplunkTrust
SplunkTrust
index="apache_logs" 
| stats count by request 
| eval request=split(request,"/")
| eval request="/".mvindex(request,1)
| top request limit=0 useother=f
| eval request=request." (".count." events, ".round(percent,2)."%)"

JaredYong
Explorer

Hi I have tried your solution, but it seems like its all categorized under /backend in the result, showing 30 events, while i should have 133 events. upon closer inspection, I noticed that each of the 30 events have their own count, which adds up to 133. How should I modify the solution such that it shows 133 instead of 30?

JaredYong_0-1634558225419.png

 

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Change the order of the commands so that the directory is resolved before the counting

index="apache_logs" 
| eval request=split(request,"/")
| eval request="/".mvindex(request,1)
| stats count by request 
| top request limit=0 useother=f
| eval request=request." (".count." events, ".round(percent,2)."%)"
0 Karma

venkatasri
SplunkTrust
SplunkTrust

Hi @JaredYong 

Can't give you a final query, however you can try using the combination of field extraction of /directory/ and stats it.

Example:

<your_base_query> "GET"
| rex field=request "\/(?<dir>\w+)\/" 
| stats count by dir

--

An upvote would be appreciated if this reply helps!

 

Tags (1)

JaredYong
Explorer

one slight problem though, i am unable to put in the percentage for the pie chart, am i missing something here?

0 Karma

venkatasri
SplunkTrust
SplunkTrust

@JaredYong  Are you good with pie chart?

 

Tags (1)
0 Karma

JaredYong
Explorer

Thank you for this solution! 

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Mastering Threat Intelligence in ES 8.5, Splunk AI Assistant v2, and More from Splunk ...

Splunk Lantern is Splunk’s customer success center that provides practical guidance from Splunk experts on key ...

Break the Build: Inside the KubeDoom Lounge at .conf26

    You step up to the machine. The pixelated corridors of a certain 1993 FPS load in front of you, EMP Pulse ...

Splunk Auto Ingestion Parallel Pipeline Scaling

Why this feature matters Many Splunk environments experience ingestion pressure long before the host is fully ...