Splunk Search

How to display success rate as 100 if no API calls are invoked?

rgopal88
New Member

Please help me in the below search query

index=Index1 sourcetype="Tablename" CounterName="Number of Successful API calls" OR CounterName="Number of Failed API calls" OR CounterName="Number of Request API calls" 
| eval Fail=if(match(CounterName,"Number of Failed API calls"),Value,0) 
| eval Success=if(match(CounterName,"Number of Successful API calls"),Value,0) 
| eval Total =Success+Fail 
| eventstats sum(Success) as Success,Sum(Total) as Total by CounterApiName 
| eval SuccessRate= (Success/Total)*100 
| timechart limit=10000 span=30m values(SuccessRate) by CounterApiName

This is showing as 0.00% when no API calls were triggered. I need to display 100% as success rate if no API calls are triggered

Tags (3)
0 Karma

elliotproebstel
Champion

You can just add a check on your penultimate line by replacing this:

| eval SuccessRate= (Success/Total)*100 

with:

| eval SuccessRate=if(Total=0, 100, (Success/Total)*100 )

That way, if Total was 0, then your SuccessRate will be 100, as desired. If Total was not 0, then it will be calculated as usual.

Get Updates on the Splunk Community!

Index This | When is October more than just the tenth month?

October 2025 Edition  Hayyy Splunk Education Enthusiasts and the Eternally Curious!   We’re back with this ...

Observe and Secure All Apps with Splunk

  Join Us for Our Next Tech Talk: Observe and Secure All Apps with SplunkAs organizations continue to innovate ...

What’s New & Next in Splunk SOAR

 Security teams today are dealing with more alerts, more tools, and more pressure than ever.  Join us for an ...