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!

Splunk Enterprise Security(ES) 7.3 is approaching the end of support. Get ready for ...

Hi friends!    At Splunk, your product success is our top priority. With Enterprise Security (ES), we're here ...

Splunk Enterprise Security 8.x: The Essential Upgrade for Threat Detection, ...

Watch On Demand the Tech Talk, and empower your SOC to reach new heights! Duration: 1 hour  Prepare to ...

Splunk Observability for AI

Don’t miss out on an exciting Tech Talk on Splunk Observability for AI!Discover how Splunk’s agentic AI ...