Splunk Search

How to get the stats for variable with a certain value ?

aasiaa
Path Finder

Hi, 

I am building alert in Splunk. I have a log with 6 different variables, but I am actually interested only in 4 of them (A, B, C and D). Those variables usually have a value which is a number like 50 but it can also be 'unknown'

this is a log sample
event
{ 

      responseStatus: 200,
       calculationBreakdown: {
         evaluation: { 
           A: unknown
           Bunknown
           C: unknown
           Dunknown
           E50
           Funknown
           }
      }

}

I am trying to do the stats for number of 'unknown' values for each variable and total calls; Then I can calculate percentage of 'unknown' for each which is treated as error and then fire my alert based on those stats

So I tried simple query:

index=someIndex app=someApp event.responseStatus=200 
| stats count as total,  sum(eval(if('event.calculationBreakdown.evaluation.A'==unknown, 1, 0))) as total_errors_for_A

wanted to do the same for errors for B, C and D, but this does not work at all, it just calculates total for all the requests but 0 for errors_A and I know there are some A =. unknown in the stats so it should be counted; 

when I change sum to count it shows the same number in both columns for total and for total_errors_for_A

I also tried different quotes for 'event.calculationBreakdown.evaluation.A' and unknown, single / double / no quotes

also added spath 'event.calculationBreakdown.evaluation.A' before | stats but that does not change anything

Is anyone able to help? I am pretty sure it is something super simple, but my mind goes blank 😞

thanks a million

 

Labels (1)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust
| stats count as total, sum(eval(if('event.calculationBreakdown.evaluation.A'=="unknown", 1, 0))) as total_errors_for_A, sum(eval(if('event.calculationBreakdown.evaluation.B'=="unknown", 1, 0))) as total_errors_for_B, sum(eval(if('event.calculationBreakdown.evaluation.C'=="unknown", 1, 0))) as total_errors_for_C, sum(eval(if('event.calculationBreakdown.evaluation.D'=="unknown", 1, 0))) as total_errors_for_D

View solution in original post

ITWhisperer
SplunkTrust
SplunkTrust
| stats count as total, sum(eval(if('event.calculationBreakdown.evaluation.A'=="unknown", 1, 0))) as total_errors_for_A, sum(eval(if('event.calculationBreakdown.evaluation.B'=="unknown", 1, 0))) as total_errors_for_B, sum(eval(if('event.calculationBreakdown.evaluation.C'=="unknown", 1, 0))) as total_errors_for_C, sum(eval(if('event.calculationBreakdown.evaluation.D'=="unknown", 1, 0))) as total_errors_for_D

aasiaa
Path Finder

@ITWhisperer thank you so much, I was sure I used all the combination of quotes, but surely I missed to try single for field and double for value. Thank you so much, it works 

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!

Mastering Threat Intelligence in ES 8.5, Splunk AI Assistant v2, and More from Splunk ...

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

Break the Build: Inside the KubeDoom Lounge at .conf26

    You step up to the machine. The pixelated corridors of a certain 1993 FPS load in front of you, EMP Pulse ...

Splunk Auto Ingestion Parallel Pipeline Scaling

Why this feature matters Many Splunk environments experience ingestion pressure long before the host is fully ...