Splunk Search

Adding two stat results using one common field

husainpatanwala
Engager

Hi guys I have two stats

index |Exception| count

index |Error |count

I want is something like this :

index |Exception|Error |count .

count should be shown for exceptions where it is present for an index and same for Error.

something like this

 

index                 Exception                                   Error              count

index_1           ArithmeticException                                         50

index_2                                                                   loginerror         2

index_1                                                                   inputerror        5

the count shouldnt mess up due to same index.Please help !

 

Labels (5)
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Try this

search
| stats count by index exception
| append [
   search
  | stats count by index error
  ]

husainpatanwala
Engager

thanks mate,this one seems to be working.

0 Karma

tscroggins
Influencer

@husainpatanwala 

stats omits output with null values in the by clause. The simplest way to achieve your desired output where count is greater than zero is to assign empty string values to Exception and Error when they're null:

| eval Exception=coalesce(Exception, ""), Error=coalesce(Error, "")
| stats count by index Exception Error

The coalesce() eval function is similar to the SQL COALESCE() function and returns the first non-null value in the argument list.

To include Exception and Error values where count is zero, you'll need to define a list of known Exception and Error values, append the list to your output, sort the list by descending count values, and deduplicate the Exception and Error output. Is this your intent?

Get Updates on the Splunk Community!

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

New Release | Splunk Cloud Platform 10.1.2507

Hello Splunk Community!We are thrilled to announce the General Availability of Splunk Cloud Platform 10.1.2507 ...

🌟 From Audit Chaos to Clarity: Welcoming Audit Trail v2

🗣 You Spoke, We Listened  Audit Trail v2 wasn’t written in isolation—it was shaped by your voices.  In ...