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!

Modern way of developing distributed application using OTel

Recently, I had the opportunity to work on a complex microservice using Spring boot and Quarkus to develop a ...

Enterprise Security Content Update (ESCU) | New Releases

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

Archived Metrics Now Available for APAC and EMEA realms

We’re excited to announce the launch of Archived Metrics in Splunk Infrastructure Monitoring for our customers ...