Splunk Search

How to get stats count to include zero count?

Upas02
Path Finder

Hi,
I have a lookup file like this -

EngineName
Engine1
Engine2
Engine3

I need to find the engine where event count is zero for last 5 minutes.

But when I am checking the number of events for each engine using this query -

index=myindex [ | inputlookup PriorityEngines | fields EngineName ] | stats count by EngineName

It shows only engines which have more than zero event count

How do I get the name of engines with zero event count in last 5 mins?
I saw few other questions in splunk answers but the queries were too complex and they didnt work for me.
Isnt there any standard way to include zero count value?

1 Solution

KailA
Contributor

Hello,

What about something like that

index=myindex  [ | inputlookup PriorityEngines | fields EngineName ]
| stats count as cnt_EngineName by EngineName
| append 
   [ inputlookup PriorityEngines | fields EngineName ]
| fillnull cnt_EngineName
| stats sum(cnt_EngineName) as count BY EngineName

It should do the trick, right ?

Kail

View solution in original post

KailA
Contributor

Hello,

What about something like that

index=myindex  [ | inputlookup PriorityEngines | fields EngineName ]
| stats count as cnt_EngineName by EngineName
| append 
   [ inputlookup PriorityEngines | fields EngineName ]
| fillnull cnt_EngineName
| stats sum(cnt_EngineName) as count BY EngineName

It should do the trick, right ?

Kail

Upas02
Path Finder

@KailA
Awesome, it worked perfect. Thanks a ton.

0 Karma

FrankVl
Ultra Champion

What you are doing is filtering the data in the index based on what is in the lookup, that will never show you any results other than what is in the index. So you would need to start from the lookup and then add the info from the index.

| inputlookup PriorityEngines | fields EngineName
| eval count = 0
| append [
  | search index=myindex | stats count by EngineName
]
| stats max(count) as count by EngineName
0 Karma

Upas02
Path Finder

@FrankVl
This solution is not working for me for 2 reasons,
First, I have more than 300 engines in my index and about 19 engines in the lookup. I do not want to get count for 300 engines, interested only in the 19 engines that are there in my lookup.

Secondly, the event count is coming incorrect for some of the engines.

0 Karma

FrankVl
Ultra Champion

In that case you could still add the subsearch into the appended search similar to how you had it before.

How the event count can be wrong I don’t know. I’m using the same stats command you had originally.

0 Karma

Upas02
Path Finder

But the main point still remains that I need to see engines with event count as 0 which I am not able to see. Only events with greater than zero is coming in the results.
Result i am getting -
EngineName count
Engine1 225
Engine2 567

Result I want to see -
EngineName count
Engine1 225
Engine2 567
Engine3 0
Engine4 0

0 Karma

FrankVl
Ultra Champion

Not sure what you did exactly, but the following should work just fine. It is pretty much the same as the other answer which you accepted:

 | inputlookup PriorityEngines | fields EngineName
 | eval count = 0
 | append [
   | search index=myindex [ | inputlookup PriorityEngines | fields EngineName ] | stats count by EngineName
 ]
 | stats max(count) as count by EngineName

lugoon
Explorer

This works and makes total sense. First initialize values in the lookup table and then craft an appended search that will perform stats from the search and populate the lookup table.

It's Gold Jerry, Gold Jerry!

 

 

0 Karma
Get Updates on the Splunk Community!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...