Splunk Search

How to write search to find error percentage for each group?

kimberlytrayson
Path Finder

My data looks as follows:

host col2 
---- ----
A SUCCESS
A ERROR
B ERROR
B SUCCESS
B SUCCESS
C ERROR

Here is the desired output:

host Total_rows_for_this_host Errors_for_this_host ErrorPercentage
---- ------------------------ -------------------- --------------
A 2 1 50
B 3 1 33
C 1 1 100

For every host, we need to find the error percentage.

What query could I use? Thank you.

Labels (1)
0 Karma
1 Solution

gcusello
SplunkTrust
SplunkTrust

Hi @kimberlytrayson,

you have to use the stats command, something like this:

<your_search>
| stats count AS Total_rows_for_this_host count(eval(col2="ERROR")) AS Errors_for_this_host BY host
| eval ErrorPercentage=round(Errors_for_this_host/Total_rows_for_this_host*100,2)

Ciao,

Giuseppe

View solution in original post

gcusello
SplunkTrust
SplunkTrust

Hi @kimberlytrayson,

you have to use the stats command, something like this:

<your_search>
| stats count AS Total_rows_for_this_host count(eval(col2="ERROR")) AS Errors_for_this_host BY host
| eval ErrorPercentage=round(Errors_for_this_host/Total_rows_for_this_host*100,2)

Ciao,

Giuseppe

Get Updates on the Splunk Community!

Stay Connected: Your Guide to July and August Tech Talks, Office Hours, and Webinars!

Dive into our sizzling summer lineup for July and August Community Office Hours and Tech Talks. Scroll down to ...

Edge Processor Scaling, Energy & Manufacturing Use Cases, and More New Articles on ...

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Get More Out of Your Security Practice With a SIEM

Get More Out of Your Security Practice With a SIEMWednesday, July 31, 2024  |  11AM PT / 2PM ETREGISTER ...