Splunk Search

Print number of returned results with data if > 10,000

OldManEd
Builder

I have a “stats” search that returns millions of results. Splunk can only show 10,000. That’s OK but what I would like is the very first row on the search results page to show an accurate count of the number of results and then the 10,000 rows of data, in table format that I’m getting now, after that. Is this possible?
~Ed

0 Karma

OldManEd
Builder

OK, here's what I came up with that works for me. I used the "dedup" and "accum" functions of Splunk. The dedup got rid of duplicate events and the accum gave me a running total. To get the total number of results, I simply run a sort on the resulting "total_count" column. Thanks for everyone's help on this one.

index="indexname" source="logname" host="*partialhostname*" | eval fieldNameTotal = fieldname1."-".fieldname2 | dedup fieldNameTotal | stats count by fieldNameTotal, fieldname3 | accum count AS total_count
0 Karma

somesoni2
Revered Legend

One more option that your can try.

index="indexname" source="logname" host="partialhostname" | eval fieldNameTotal = fieldname1."-".fieldname2 | stats count by fieldnameTotal, fieldname3 | addcoltotals | eval fieldname3 =if(isnull(fieldname3), "#Total Rows",fieldname3 ) | sort fieldname3
0 Karma

somesoni2
Revered Legend

It should be the first row in the table and "#Total Rows" should appear under fieldname3 column.

0 Karma

OldManEd
Builder

I tried the search above and I got my table fine, but I couldn't find the "#Total Rows" anywhere in the report.

0 Karma

martin_mueller
SplunkTrust
SplunkTrust

A caveat for using sort: It doesn't really like large result sets. You will at least need to specify a count of 0 to overcome the default restriction of 10000 events.

0 Karma

martin_mueller
SplunkTrust
SplunkTrust

You could append this to your search to get a count of events added to each row:

... | eventstats count
0 Karma

martin_mueller
SplunkTrust
SplunkTrust

For example you could add a PostProcess module as a sibling of your Table module, do a | stats count there, and display that in an HTML module.
That's assuming you're in an AdvancedXML view. I'm sure similar things can be done using the SplunkJS stack, not so sure about SimpleXML.

0 Karma

OldManEd
Builder

Martin, how would I do this?

0 Karma

martin_mueller
SplunkTrust
SplunkTrust

If you already have a field called count you can do this instead:

... | eventstats count as total_count

Here's an entirely different idea: Leave your table as-is, and add an HTML panel above the table that prints out the number of results separately from the table.

OldManEd
Builder

Yes, this will work but not really what I'm looking for. Bedsides, I'm already using the "stats" and "count" field. The search looks like this;

index="indexname" source="logname" host="partialhostname" | eval fieldNameTotal = fieldname1."-".fieldname2 | stats count by fieldnameTotal, fieldname3 | sort fieldname3

Any other ideas?

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, ...