Splunk Search

Splunk query  to display % failures

VS0909
Communicator

Need help with a Splunk query  to display % failures 

% failures = A1/A2 *100

A1= Total number of events returned by the below query:

index="abc"  "searchTermForA1"

 

A2= Total number of events returned by the below query:

index="xyz"  "searchTermForA2"

Please help with the query.

Thanks!

 

Labels (6)
0 Karma

VS0909
Communicator

(index="abc" "searchTermForA1") OR (index="xyz" "searchTermForA2")
| stats count(eval(index="abc")) as A1 count(eval(index="xyz")) as A2

 is not giving the correct count for A1 and A2 , when compared to executing index="abc" "searchTermForA1" and   index="xyz" "searchTermForA2" separately.

 

Need help with a Splunk query  to display % failures 

% failures = A1/A2 *100

A1= Total number of events returned by the below query:

index="abc"  "searchTermForA1"

 

A2= Total number of events returned by the below query:

index="xyz"  "searchTermForA2"

Please help with the query.

Thanks!

 

0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust
(index="abc" "searchTermForA1") OR (index="xyz" "searchTermForA2")
| stats count(eval(index="abc")) as A1 count(eval(index="xyz")) as A2

This should work. Can you please try this?

index="abc" "searchTermForA1" | stats count as A1 | appendcols [ search index="xyz" "searchTermForA2"| stats count as A2]
| eval "% failures" = A1/A2 *100

 

kamlesh_vaghela
SplunkTrust
SplunkTrust

@VS0909 

Try something like this.

(index="abc"  "searchTermForA1") OR (index="xyz"  "searchTermForA2")
| stats count(eval(index="abc")) as A1 count(eval(index="xyz")) as A2
| eval "% failures" = A1/A2 *100

0 Karma

VS0909
Communicator

@kamlesh_vaghela  Thanks for the reply!

But for "A1= count(eval(index="abc"))" 

My requirement is A1= Total number of events returned by the below query:

index="abc"  "searchTermForA1"

A2= Total number of events returned by the below query:

index="xyz"  "searchTermForA2"

A1  and A2 should include count filter by index and search term.

0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

@VS0909 

Events are already filtered with

(index="abc"  "searchTermForA1") OR (index="xyz"  "searchTermForA2")

 

So only index filter is enough to identify events,

| stats count(eval(index="abc")) as A1 count(eval(index="xyz")) as A2

 

So just try and let me know if any issue.

Thanks
KV
▄︻̷̿┻̿═━一   ?

If any of my reply helps you to solve the problem Or gain knowledge, an upvote would be appreciated.

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!

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas     Cisco Live 2026 is almost here, and this ...

What Is the Name of the USB Key Inserted by Bob Smith? (BOTS Hint, Not the Answer)

Hello Splunkers,   So you searched, “what is the name of the usb key inserted by bob smith?”  Not gonna lie… ...

Automating Threat Operations and Threat Hunting with Recorded Future

    Automating Threat Operations and Threat Hunting with Recorded Future June 29, 2026 | Register   Is your ...