Splunk Search

Calculate percentage by eval status

Noah
Explorer

Hi Everyone! 

Could you please help, how to calculate (UP percentage) by app_service 

I have the query as: 

eval status=if(success="successful .Statuscode:200", "UP", "DOWN"
| table   app_service    status

I get the table I need, but I have difficulty calculating the "UP" percentage and total percentage per app_service from the above query

Thank you 

Labels (4)
0 Karma
1 Solution

venkatasri
SplunkTrust
SplunkTrust

Hi @Noah 

Can you try this?

| makeresults 
| eval success="successful .Statuscode:200" , app_service="jobber"
| eval status=if(success="successful .Statuscode:200", "UP", "DOWN") 
| stats count, count(eval(status="UP")) as up_count by app_service 
| eval perc= round((up_count/count) * 100,4)
| table count up_count app_service perc

An upvote would be appreciated and Accept solution if this reply helps!

View solution in original post

venkatasri
SplunkTrust
SplunkTrust

Hi @Noah 

Can you try this?

| makeresults 
| eval success="successful .Statuscode:200" , app_service="jobber"
| eval status=if(success="successful .Statuscode:200", "UP", "DOWN") 
| stats count, count(eval(status="UP")) as up_count by app_service 
| eval perc= round((up_count/count) * 100,4)
| table count up_count app_service perc

An upvote would be appreciated and Accept solution if this reply helps!

Noah
Explorer

Thank you @venkatasri Venkatasri! This definitely helped with some modifications. Much appreciated! 

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Splunk AI Assistant for SPL vs. ChatGPT: Which One is Better?

In the age of AI, every tool promises to make our lives easier. From summarizing content to writing code, ...

Data Persistence in the OpenTelemetry Collector

This blog post is part of an ongoing series on OpenTelemetry. What happens if the OpenTelemetry collector ...

Thanks for the Memories! Splunk University, .conf25, and our Community

Thank you to everyone in the Splunk Community who joined us for .conf25, which kicked off with our iconic ...