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 | What did the zero say to the eight?

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

Splunk Observability Cloud's AI Assistant in Action Series: Onboarding New Hires & ...

This is the fifth post in the Splunk Observability Cloud’s AI Assistant in Action series that digs into how to ...

Now Playing: Splunk Education Summer Learning Premieres

It’s premiere season, and Splunk Education is rolling out new releases you won’t want to miss. Whether you’re ...