Splunk Search

search language

francly
Explorer

Hi, how do I get subtotal count for each Host and Total for all count, in additional count for all different status.

Host                            Status                             Count

HostADisconnected1
HostARunning19
HostARunningWithErrors2
HostABadConnectivity2
HostBDisabled2
HostBDisconnected1
HostBRunning17
HostBRunningWithErrors5
HostCBadConnectivity1
HostCRunning7
HostCRunningWithErrors5
Labels (1)
0 Karma
1 Solution

PickleRick
SplunkTrust
SplunkTrust

You're using count as a splunk function whereas in original post count is a field. So your count will just count the counts 😉 and what seems to be really needed is a sum of counts.

And your construction will yield some strange results.

What the OP wanted was simply one:

<original search> | stats sum(Count) by Host | addtotals row=f col=t labelfield=Host

and two:

<original search>| stats sum(Count) by Status | <optionaly addtotals as in example above>

 

View solution in original post

Tags (1)
0 Karma

PickleRick
SplunkTrust
SplunkTrust

You need two different searches - one to sum count over hosts (and then do addtotals to get total sum) and another one to sum over statuses. That's the simplest solution I think

0 Karma

francly
Explorer

thanks for response, can you provide the query.

Tags (1)
0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @francly,

you could try something like this.

index=your_index
| stats count BY host Status
| append [ search 
     index=your_index
     | stats count BY host
     | eval Status="Total"
     ]
| sort host Status
| rename host AS Host

Ciao.

Giuseppe

0 Karma

PickleRick
SplunkTrust
SplunkTrust

You're using count as a splunk function whereas in original post count is a field. So your count will just count the counts 😉 and what seems to be really needed is a sum of counts.

And your construction will yield some strange results.

What the OP wanted was simply one:

<original search> | stats sum(Count) by Host | addtotals row=f col=t labelfield=Host

and two:

<original search>| stats sum(Count) by Status | <optionaly addtotals as in example above>

 

Tags (1)
0 Karma
Get Updates on the Splunk Community!

Troubleshooting the OpenTelemetry Collector

  In this tech talk, you’ll learn how to troubleshoot the OpenTelemetry collector - from checking the ...

Adoption of Infrastructure Monitoring at Splunk

  Splunk's Growth Engineering team showcases one of their first Splunk product adoption-Splunk Infrastructure ...

Modern way of developing distributed application using OTel

Recently, I had the opportunity to work on a complex microservice using Spring boot and Quarkus to develop a ...