Splunk Search

show zero in count for stats command

venky1544
Builder

i want to show the count from host as zero if the process is not found however not able to find 0 count the host disappears if process is not found

index=oslogs sourcetype=ps COMMAND="process1"
|stats count by host,COMMAND

result :-

host1  java 12
host2  java 3
host4  java 4

Expected result
host1 12
host2 3
host3 0
host4 4

Labels (1)
0 Karma

richgalloway
SplunkTrust
SplunkTrust

The stats command cannot count what isn't there.  It can't fill in missing values because the set of possible missing values is infinite.  You have to have a list of possible host names and use that to insert zeroes for missing hosts.  See this blog entry for a good write-up on it.

https://www.duanewaddle.com/proving-a-negative/

---
If this reply helps you, Karma 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!

Monitoring AI Agents with Splunk Observability Cloud

Let’s say I’m running a travel planning AI app in production. A user asks for three concise hotel options in ...

[Puzzles] Solve, Learn, Repeat: Tiling

This puzzle (first published here) is based on finding groups of tessellated tiles (inspired by floor tiles I ...

SOK it to Me: Top 3 Benefits of Using Splunk Operator on Kubernetes that’ll Make ...

    Thursday, July 9, 2026  |  11:00AM–12:00PM PDT Duration: 1 hour (includes Q&A) Managing can feel like a ...