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
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

May 2026 Splunk Expert Sessions: Security & Observability

Level Up Your Operations: May 2026 Splunk Expert Sessions Whether you are refining your security posture or ...

Network to App: Observability Unlocked [May & June Series]

In today’s digital landscape, your environment is no longer confined to the data center. It spans complex ...

SPL2 Deep Dives, AppDynamics Integrations, SAML Made Simple and Much More on Splunk ...

Splunk Lantern is Splunk’s customer success center that provides practical guidance from Splunk experts on key ...