Splunk Search

How to compare success/failure by status

mwolfe
Engager

I've got data so:

"[clientip]  [host] - [time] [method] [uri_path] [status] [useragent]" ..  
and do the following search:

 

index=web  uri_path="/somepath" status="200" OR status="400"
| rex field=useragent "^(?<app_name>[^/]+)/(?<app_version>[^;]+)?\((?<app_platform>[^;]+); *"
| eval app=app_platform+" "+app_name+" "+app_version

 


I've split up the useragent just fine and verified the output. I want to now compare status  by "app".
So I've added the following:

 

| stats count by app, status

 


Which gives me:

appstatuscount

android app 1.0

2005000

ios app 2.0

4003

android app 1.1

200500

android app 1.0

40012

ios app 2.0

2003000


How can I compare, for a given "app" (combo of platform, name, version) the rate of success where success is when the response = 200 and failure if 400. I understand that I need to take success and divide by success + failure count.. But how do I combine this data? 
Also note that I need to consider that some apps may not have any 400 errors. 

Labels (1)
0 Karma
1 Solution

gcusello
SplunkTrust
SplunkTrust

Hi @mwolfe ,

don't use sum but count:

index=web  uri_path="/somepath" status="200" OR status="400"
| rex field=useragent "^(?<app_name>[^/]+)/(?<app_version>[^;]+)?\((?<app_platform>[^;]+); *"
| eval app=app_platform+" "+app_name+" "+app_version
| eval success=if(status=200,1,0)
| eval failure=if(status=400,1,0)
| stats 
     count(failure) AS fail_count
     count(success) AS success_count
     BY app
| eval success_rate=round((success_count / (success_count + fail_count))*100,1)
| table app success_rate

otherwise, you could insert the eval in the stats:

index=web  uri_path="/somepath" status="200" OR status="400"
| rex field=useragent "^(?<app_name>[^/]+)/(?<app_version>[^;]+)?\((?<app_platform>[^;]+); *"
| eval app=app_platform+" "+app_name+" "+app_version
| stats 
     count(eval(status=400)) AS fail_count
     count(eval(status=200)) AS success_count
     BY app
| eval success_rate=round((success_count / (success_count + fail_count))*100,1)
| table app success_rate

Ciao.

Giuseppe

View solution in original post

0 Karma

mwolfe
Engager

I think I got it 

| eval success=if(status=200,1,0)
| eval failure=if(status=400,1,0)
| stats sum(failure) as fail_sum, sum(success) as success_sum by app
| eval success_rate=round((success_sum / (success_sum + fail_sum))*100,1)
| table app, success_rate
0 Karma

PickleRick
SplunkTrust
SplunkTrust

You can also check out two nice commands - xyseries and untable which can be used to (de)tabularize such data series.

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @mwolfe ,

don't use sum but count:

index=web  uri_path="/somepath" status="200" OR status="400"
| rex field=useragent "^(?<app_name>[^/]+)/(?<app_version>[^;]+)?\((?<app_platform>[^;]+); *"
| eval app=app_platform+" "+app_name+" "+app_version
| eval success=if(status=200,1,0)
| eval failure=if(status=400,1,0)
| stats 
     count(failure) AS fail_count
     count(success) AS success_count
     BY app
| eval success_rate=round((success_count / (success_count + fail_count))*100,1)
| table app success_rate

otherwise, you could insert the eval in the stats:

index=web  uri_path="/somepath" status="200" OR status="400"
| rex field=useragent "^(?<app_name>[^/]+)/(?<app_version>[^;]+)?\((?<app_platform>[^;]+); *"
| eval app=app_platform+" "+app_name+" "+app_version
| stats 
     count(eval(status=400)) AS fail_count
     count(eval(status=200)) AS success_count
     BY app
| eval success_rate=round((success_count / (success_count + fail_count))*100,1)
| table app success_rate

Ciao.

Giuseppe

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @mwolfe ,

good for you, see next time!

Ciao and happy splunking

Giuseppe

P.S.: Karma Points are appreciated by all the contributors 😉

0 Karma
Get Updates on the Splunk Community!

Introducing the Splunk Developer Program!

Hey Splunk community! We are excited to announce that Splunk is launching the Splunk Developer Program in ...

Splunkbase Year in Review 2024

Reflecting on 2024, it’s clear that innovation and collaboration have defined the journey for Splunk ...

Developer Spotlight with Brett Adams

In our third Spotlight feature, we're excited to shine a light on Brett—a Splunk consultant, innovative ...