Splunk Search

Splunk stats count for several search

vintik
Engager

Hello,

I have ~15 the same queries with a little difference:

(index=SOME_INDEX sourcetype=SOME_SOURCE source=... 
| eval API=CASE(searchmatch("xxx"), "yyy", ...) 
| search API=WebResponse
| eval Status=case(...) 
| stats avg(dur) AS Avg by status_code
| stats count by status_code

...

(index=SOME_INDEX sourcetype=SOME_SOURCE source=... 
| eval API=CASE(searchmatch("xxx"), "yyy", ...) 
| search API=AppResponse
| eval Status=case(...) 
| stats avg(dur) AS Avg by status_code
| stats count by status_code

So, all my queries are different only in one place - | search API=XXX and return result like:

| status_code | count |
|  201        |  10   |
|  404        |  28   |
etc

How I can combine all above queries into one and get result as (or something like this):

    | status_code | count(AppResponse) | count(WebResponse) | count(Other) |
    |  201        |  10                |  0                  |  0   |
    |  404        |  28                |  3                  |   0  |

?

0 Karma

somesoni2
Revered Legend

Try this (there were two stats at the end of your search in question which seems wrong to me, because count will always be 1 in second stats.

(index=SOME_INDEX sourcetype=SOME_SOURCE source=... 
 | eval API=CASE(searchmatch("xxx"), "yyy", ...) 
 | search API=WebResponse
 | eval Status=case(...) 
 | chart count AS Avg by status_code API
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!

ATTENTION: We’re Moving! (AGAIN!)

The Splunk Community Slack is undergoing a system migration to keep our workspace secure and ...

Deep Dive: Optimizing Telemetry Pipelines in Splunk Observability Cloud

In this session, we will peel back the layers of Splunk Observability Cloud’s cost-optimization features. ...

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...