Splunk Search

calculate percentage of a each ErrorCode field by servername

indeed_2000
Motivator

Hi

how can I calculate percentage of a each ErrorCode field by servername?

here is the spl:

index="my_index"
| rex field=source "\/log\.(?<servername>\w+)."
| rex "Err\-ErrorCode\[(?<ErrorCode>\d+)"

expected output:

Servername     ErrorCode      Percentage 

server1             404                    50%

                             500                    40%

                             200                    10%

server2             500                    50%

                             404                    45%

                             200                    5%

 

any idea?

 Thanks 

Labels (5)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust
index="my_index"
| rex field=source "\/log\.(?<servername>\w+)."
| rex "Err\-ErrorCode\[(?<ErrorCode>\d+)"
| eventstats count as servercount by servername
| stats count as errorcount values(servercount) as servercount by servername ErrorCode
| eval Percentage=round(100*errorcount/servercount,2)
| table servername ErrorCode Percentage

View solution in original post

ITWhisperer
SplunkTrust
SplunkTrust
index="my_index"
| rex field=source "\/log\.(?<servername>\w+)."
| rex "Err\-ErrorCode\[(?<ErrorCode>\d+)"
| eventstats count as servercount by servername
| stats count as errorcount values(servercount) as servercount by servername ErrorCode
| eval Percentage=round(100*errorcount/servercount,2)
| table servername ErrorCode Percentage

indeed_2000
Motivator

Thank you for answer, is it possible to add count, like below?

Servername     ErrorCode      Percentage      count

server1                 404                    50%                       456

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Just add it to the table command

| table servername ErrorCode Percentage errorcount
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 ...