Splunk Search

Using a stats avg function after an eval case command to categorise

ebs
Communicator

Hi,

I have a requirement where we need to categorise events based on the url into 4 separate categories, then calculate the average response time for each category. Finally we want to display all the averages by category together in a stats table, is there an easy way to do this?

Labels (3)
0 Karma
1 Solution

gcusello
SplunkTrust
SplunkTrust

Hi @ebs,

the problem is to find a rule to categorize urls, if e.g. you have this rule:

in the uri field you have

localhost/* --> Cat. A

community/* --> Cat. B

splunk.com/ --> Cat. C

others--> Cat. D

you can try something like this:

index=your_index
| eventstats count As total
| eval type="D"
| eval type=case(match(uri,"localhost"),"A",match(uri,"community"),"B", match(uri,"splunk.com"),"C")
| stats avg(response_time) AS response_time count values(total) AS total BY type
| eval perc=round(count/total*100,2)
| table type response_time perc

Ciao.

Giuseppe

 

View solution in original post

gcusello
SplunkTrust
SplunkTrust

Hi @ebs,

the problem is to find a rule to categorize urls, if e.g. you have this rule:

in the uri field you have

localhost/* --> Cat. A

community/* --> Cat. B

splunk.com/ --> Cat. C

others--> Cat. D

you can try something like this:

index=your_index
| eventstats count As total
| eval type="D"
| eval type=case(match(uri,"localhost"),"A",match(uri,"community"),"B", match(uri,"splunk.com"),"C")
| stats avg(response_time) AS response_time count values(total) AS total BY type
| eval perc=round(count/total*100,2)
| table type response_time perc

Ciao.

Giuseppe

 

gcusello
SplunkTrust
SplunkTrust

Hi @ebs,

good for you, see next time!
Ciao and happy splunking.

Giuseppe

P.S.: Karma Points are appreciated 😉

0 Karma
Get Updates on the Splunk Community!

What's new in Splunk Cloud Platform 9.1.2312?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2312! Analysts can ...

What’s New in Splunk Security Essentials 3.8.0?

Splunk Security Essentials (SSE) is an app that can amplify the power of your existing Splunk Cloud Platform, ...

Let’s Get You Certified – Vegas-Style at .conf24

Are you ready to level up your Splunk game? Then, let’s get you certified live at .conf24 – our annual user ...