Splunk Search

How to edit my search to calculate failure percentage through Splunk logs?

eleena1994
New Member

I have logs like:
"The request failed"
"The request succeeded"
"The request failed"
"The request failed"
"The request succeeded"

I want to calculate failure % every day on the basis of the string ("failed" or "succeeded")

please help me correct this search (marked in ***):

...base search... | timechart span=1d ***eval((count("failed"))/((count("failed"))+(count ("succeeded"))))*** as failureRate
Tags (2)
0 Karma

aaraneta_splunk
Splunk Employee
Splunk Employee

Hi @eleena1994 - Looks like you have a few answers to choose from 🙂 Did any one of the answers below help resolve your question? If yes, please don't forget to resolve your post by clicking "Accept" below the best answer. If no, please leave a comment with some feedback. Thanks!

0 Karma

gokadroid
Motivator

Try this:

your base search | rex "The request (?<status>\w+)" 
| timechart span=1d count(eval(status="failed")) as failed,  count(eval(status="succeeded")) as success
| eval failureRate=(failed/(failed+success))*100
0 Karma

somesoni2
SplunkTrust
SplunkTrust

Try like this

your base search | rex "The request (?<status>\w+)" | timechart span=1d count by status | eval "%failed"=round(failed*100/(failed+succeeded),1) 
0 Karma

cmerriman
Super Champion

try something like this:

...| timechart span=1d count("failed") as failed count("succeeded") as succeeded|eval failureRate=failed/(failed+succeeded)|fields - failed - succeeded

you might need to add something like count(match(x,"failed")) into the timechart command instead of the count("failed")

0 Karma
Get Updates on the Splunk Community!

What's new in Splunk Cloud Platform 9.1.2312?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2312! Analysts can ...

What’s New in Splunk Security Essentials 3.8.0?

Splunk Security Essentials (SSE) is an app that can amplify the power of your existing Splunk Cloud Platform, ...

Let’s Get You Certified – Vegas-Style at .conf24

Are you ready to level up your Splunk game? Then, let’s get you certified live at .conf24 – our annual user ...