Splunk Search

Do we need to use a subsearch to divide the results of one search by the results of another search to find a percentage?

splunker9999
Path Finder

Hi,

We are looking for timeout percentage from the total events.

For Ex:
1. Query1: index=datapower Time=*|stats count

2. Query2: index=datapower Time>10000|stats count

Now we are looking for results as Query1/Query2. Do we need to do this with subsearch? Can anyone help with this?

Thanks

0 Karma
1 Solution

somesoni2
SplunkTrust
SplunkTrust

Try something like this

index=datapower Time=* | stats count as Query1 count(eval(Time>10000)) as Query2 | eval Result=Query1/Query2

OR

index=datapower Time=* | eval Query2=if(Time>10000,1,0) | stats count as Query1 csum(Query2) as Query2 | eval Result=Query1/Query2

View solution in original post

jrodman
Splunk Employee
Splunk Employee

The strict answer to your question is yes, you need two searches for the general case, whether subsearches, or other methods like reusing the output of one search as input in another.

However the usual answer is to craft a search that doesn't need to handle the general case, and thus this is a comment since +somesoni2 has addressed the inquiry.

0 Karma

somesoni2
SplunkTrust
SplunkTrust

Try something like this

index=datapower Time=* | stats count as Query1 count(eval(Time>10000)) as Query2 | eval Result=Query1/Query2

OR

index=datapower Time=* | eval Query2=if(Time>10000,1,0) | stats count as Query1 csum(Query2) as Query2 | eval Result=Query1/Query2
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...