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!

Get the T-shirt to Prove You Survived Splunk University Bootcamp

As if Splunk University, in Las Vegas, in-person, with three days of bootcamps and labs weren’t enough, now ...

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...

Wondering How to Build Resiliency in the Cloud?

IT leaders are choosing Splunk Cloud as an ideal cloud transformation platform to drive business resilience,  ...