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!

Community Content Calendar, November Edition

Welcome to the November edition of our Community Spotlight! Each month, we dive into the Splunk Community to ...

October Community Champions: A Shoutout to Our Contributors!

As October comes to a close, we want to take a moment to celebrate the people who make the Splunk Community ...

Stay Connected: Your Guide to November Tech Talks, Office Hours, and Webinars!

What are Community Office Hours? Community Office Hours is an interactive 60-minute Zoom series where ...