Splunk Search

How to split the call based on TimeTaken

marinewcreater
Explorer

I would like to create a Pie chart to show how many calls took less than 100ms, 200ms, and 300ms. 

index=star env=prod |search time > 100 | stats count by time

 

How can I append > 200 and >300 in the same query? 

Labels (3)
0 Karma

acharlieh
Influencer

In addition to the `count(eval())` options with stats as have already been suggested, another option would be to create a field that classifies your events by the durations you're interested in... then stats count by that new field... 

If you have the specific ranges that you're interested in...you could use eval to construct a classifier, and then stats count by that classifier.

<base search> 
| eval classifier=case(time<100, "<100", time<200, "<200", time<300, "<300", true(), ">=300" )
| stats count by classifier

Since you have a numeric field, you could use bin to make those classifiers instead:

<base search> 
| bin time as classifier span=100
| stats count by classifier

And of course there are many other methods of creating a classifier field (single or multi-valued), but the downside to doing a simple by clause is of course is that if you don't have a particular expected range/classifier in your data, you simply won't have that particular range in your output, which depending on your use case may be alright, or may be a problem.

0 Karma

venkatasri
SplunkTrust
SplunkTrust

@marinewcreater 

You could try stats with eval something like this , grouping them by time does not create a great pie chart you could still try it depends on number of data points, use | bin to bucket them before using by time.

 

index=star env=prod | searchTime > 100 | stats count(eval(searchTime>100)) as gt_100, count(eval(searchTime>200 AND searchTime<300)) as gt_200, count(eval(searchTime>300)) as gt_300 

 

 

nmohammed
Contributor
index=star env=prod | 
chart count(eval(time <100)) AS "<100ms", count(eval(time >100 AND time <200)) AS "<200ms", count(eval(time >200 AND time <300)) AS "<300ms" 
| stats count by time 

 

try that query and select pie chart under visualizations.

marinewcreater
Explorer

Error in stats command: eval is invalid

0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...