Splunk Search

Combining 2 Queries Using Same Field

PaintItParker
Explorer

I have two queries. One gets the total number of events using the message field:

 

index=my_index sourcetype=my_sourcetype
| stats count(message) AS TotalA
| table TotalA

 

And the other uses multiple regex statements and the message field to get the total number of errors:

 

index=my_index sourcetype=my_sourcetype
| regex message = "(?:(^Problem.*)|((?i).*Issue.*)|((?i).*Error.*))"
| stats count(message) AS TotalB
| table TotalB

 

My goal is to have TotalA and TotalB side by side in a table. I would then like to divide TotalA by TotalB to get a ratio and display that alongside TotalA and TotalB in the table.

How could I go about combining these? Thanks!

Labels (4)
0 Karma
1 Solution

ericjorgensenjr
Path Finder

This should work:

 

index=my_index sourcetype=my_sourcetype 
| eval isProblem=if(match(message,"(?i)(?:problem)|(?:issue)|(?:error)"),1,0) 
| stats count as totalMessage, sum(isProblem) as countErrors
| eval ratioErrors = round(countErrors/totalMessage,4)

 

 

View solution in original post

ericjorgensenjr
Path Finder

This should work:

 

index=my_index sourcetype=my_sourcetype 
| eval isProblem=if(match(message,"(?i)(?:problem)|(?:issue)|(?:error)"),1,0) 
| stats count as totalMessage, sum(isProblem) as countErrors
| eval ratioErrors = round(countErrors/totalMessage,4)

 

 

PaintItParker
Explorer

Thank you so much!

0 Karma
Get Updates on the Splunk Community!

Splunk + ThousandEyes: Correlate frontend, app, and network data to troubleshoot ...

 Are you tired of troubleshooting delays caused by siloed frontend, application, and network data? We've got a ...

Splunk Observability for AI

Don’t miss out on an exciting Tech Talk on Splunk Observability for AI!Discover how Splunk’s agentic AI ...

🔐 Trust at Every Hop: How mTLS in Splunk Enterprise 10.0 Makes Security Simpler

From Idea to Implementation: Why Splunk Built mTLS into Splunk Enterprise 10.0  mTLS wasn’t just a checkbox ...