Splunk Search

How to default stats to zero when no rows returned?

schres1
Explorer

I have a query similar to the one below. 

index = "idx" source = "mysource"  |spath path=myField output=res|stats count by res
| where res="xyz"

Is there a way to get the search to return zero if no rows are returned? The reason Im asking for this is because this is the query Im using to populate values into a dashboard panel. If no rows are returned I would prefer the panel show zero instead of no results. 

Labels (2)
Tags (2)
0 Karma
1 Solution

etoombs
Path Finder

There might be a more graceful way someone will provide, but I generally add something like this to the end, forcing a row with a 0 value, and then doing another quick sum before displaying it.

| append
[makeresults |eval count=0]
|stats sum(count) as count

 

View solution in original post

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

This is another way to get count=0

| appendpipe
    [stats count
    | where count=0
    | eval res="xyz"]

Having said that, there may be a better way depending on your full search.

0 Karma

schres1
Explorer

Thank you! I will give this a try!

0 Karma

etoombs
Path Finder

There might be a more graceful way someone will provide, but I generally add something like this to the end, forcing a row with a 0 value, and then doing another quick sum before displaying it.

| append
[makeresults |eval count=0]
|stats sum(count) as count

 

0 Karma
Get Updates on the Splunk Community!

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...

New in Observability Cloud - Explicit Bucket Histograms

Splunk introduces native support for histograms as a metric data type within Observability Cloud with Explicit ...