Splunk Search

filter out top 10% of the results sorted in desc order

tanujsaxena
New Member

Hi all,

i am trying the below query.. i need result for only top 10% of the total result. the query i am using is

..| transaction correlationId |stats avg(duration) as "Average" min(duration) as "Minimum Response Time" max(duration) as "Maximum Response Time"

the query basically returns the time taken for execution. i need to extract data on weekly basis.

i need data for top 10% of the total value sorted to avg(duration).

Tags (3)
0 Karma

lguinn2
Legend

I believe that this will do what you want, and it will be much more efficient:

yoursearchhere
| stats range(_time) as duration by correlationId
| stats avg(duration) as Average min(duration) as "Minimum Response Time" max(duration) as "Maximum Response Time"
| sort 0 -Average
| streamstats count as row 
| eventstats count as total
| where round(row/total,0) <= .1
| fields - row total

The above gives you the top 10% based on the count of results. In other words, if you have 150 correlationIds, you will get a list of the 15 with the greatest average duration.

0 Karma

tanujsaxena
New Member

thanks a lot. i tried but somehow it is giving the result for top 50% of the total result. the no of events is 269 and the output comes out to be for top 134 events.

0 Karma

lguinn2
Legend

Leave off the last 2 lines and you will be able to see the row numbers and the total count of the rows... maybe that will help you figure out what is going on

0 Karma

somesoni2
Revered Legend

I don't completely understand the requirement here. Your stats gives you single row output, so you want to consider top 10% before the stats? OR you want to run this for multiple weeks and want to generate this single row output for top 10% week?

tanujsaxena
New Member

i want the top 10% of the total data. For ex: if i run my query for a week and i get 1000 results sorted in desc order i need output only for top 10% of the results. i.e. for top 100 lines in a result of 1000 lines.

0 Karma
Get Updates on the Splunk Community!

Index This | I’m short for "configuration file.” What am I?

May 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with a Special ...

New Articles from Academic Learning Partners, Help Expand Lantern’s Use Case Library, ...

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Your Guide to SPL2 at .conf24!

So, you’re headed to .conf24? You’re in for a good time. Las Vegas weather is just *chef’s kiss* beautiful in ...