Splunk Search

Percentage by field with search

Idodox
Engager

I'm trying to get a percentage of a field, based on a condition (filtered by search) by another field.

e.g.  percentage of 404 errors by application. So need to get the total number of requests for each application, filter to keep only 404 errors then count by application. At least that's the logic I used.

 

<unrelated part to collect proper events>
| eventstats count as total by applicationId
| search error=404
| stats count as error_404 by applicationId
| eval errorRate=((error_404/total)*100)."%"
| table applicationId, errorRate

 

 

This returns a list of applications, but no values for errorRate.
Individually, I'm able to get a result for this:

 

| stats count as total by applicationId

 



And also for this:

 

| search error=404
| stats count as error_404 by applicationId

 


But something in having them together in the flow I have doesn't work.

I also tried this which didn't work. In this instance I get values for applicationId and total. So I guess there's something wrong with how I'm getting the error_404 values.

 

| stats count as total by applicationId
| appendcols[search error=404|stats count as error_404 by applicationId]
| eval errorRate=((error_404/total)*100)."%"
| table applicationId, error_404, total, errorRate

 

Labels (2)
0 Karma
1 Solution

gcusello
SplunkTrust
SplunkTrust

Hi @Idodox ,

please see this approach:

<unrelated part to collect proper events> error=4
| eventstats count as total by applicationId
| search error=404
| stats count as error_404 values(total) AS total by applicationId
| eval errorRate=((error_404/total)*100)."%"
| table applicationId, errorRate

Ciao.

Giuseppe

View solution in original post

gcusello
SplunkTrust
SplunkTrust

Hi @Idodox ,

please see this approach:

<unrelated part to collect proper events> error=4
| eventstats count as total by applicationId
| search error=404
| stats count as error_404 values(total) AS total by applicationId
| eval errorRate=((error_404/total)*100)."%"
| table applicationId, errorRate

Ciao.

Giuseppe

Idodox
Engager

Works beautifully. Thank you!

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

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...