Splunk Search

Need help with eval

Dsrao12345
New Member

my search query :

index=index1"PrepareResponseTime= " 
| rex "PreResponseTime= (?[0-9]*) ms"  
| where PrepareResponseTime > 1000 
| eval PrepareResponseTime= "count >1000"  
| stats count by index,PrepareOrderResponseTime 
| append [search index=index2 "PrepareResponseTime= " 
| rex "PrepareResponseTime= (?[0-9]*) ms"  
| where PrepareResponseTime < 1000 | eval PrepareResponseTime= "count <1000"  

statistics results:

indexname PrepareResponseTime count
========= =================== =====
index1 count >1000 1486
index2 count <1000 6639

I would like to using eval calculate percentage like below:

(1486 * 100) / (1486 + 6639) = %

148600/8125 = 18.289 (round)

After using calculations results to be like :

round 18.29%

Tags (2)
0 Karma

renjith_nair
Legend

@Dsrao12345,

Add this to your search

| eventstats sum(count) as total
| eval perc=round((count/total)*100,2)

And your original search probably could be modified as

 (index=index1  OR  index=index2) "PrepareResponseTime= "  
 |rex "PreResponseTime= (?[0-9]) ms"
 |eval ResponseTime=if(PrepareResponseTime <1000,"count <1000","count >1000" )
 |stats count by index,ResponseTime
---
What goes around comes around. If it helps, hit it with Karma 🙂
0 Karma
Get Updates on the Splunk Community!

Introducing the Splunk Community Dashboard Challenge!

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

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer Certification at ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...