Splunk Search

How to modify query to tabulate error codes and percent failure?

9jamie
Explorer

I am trying to create a query that returns a table showing counts of different error codes and percentage of transactions that are failing (error != 0) for each service. 

service 0 3100 2000 1200 % Failure
Foo 1000 12 0 0 1.2%
Bar 100 0 3 2 5.0%

 

My query which returns the above table is: 

index=my_index | where error=0 OR error!=0 | chart count by service, error | eval "% Failure"  = round(('3100'+'2000'+'1200')/('3100'+'2000'+'1200'+'0'),2)."%"

 

How can I modify this query so that I don't need to hardcode each error code into the last part of the query, as error codes may vary?

Labels (2)
Tags (1)
0 Karma
1 Solution

johnhuang
Motivator
index=my_index error=*
| chart count by service, error
| addtotals fieldname="event_total"
| eval "% Failure"=round((event_total-'0')/(event_total)*100, 2)."%"

View solution in original post

johnhuang
Motivator
index=my_index error=*
| chart count by service, error
| addtotals fieldname="event_total"
| eval "% Failure"=round((event_total-'0')/(event_total)*100, 2)."%"
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!

SOC4Kafka - New Kafka Connector Powered by OpenTelemetry

The new SOC4Kafka connector, built on OpenTelemetry, enables the collection of Kafka messages and forwards ...

Event Series: Level up your SOC: Advancing with Splunk Enterprise Security

AI has fundamentally raised the stakes for security operations, and this three-part series is your guide to ...

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...