Splunk Search

streamstats clarification

echalex
Builder

Hi,

I'm using streamstats to calculate the median for a field and timechart to see the count of events where the field has a value less than a median.

... | streamstats median(bytes) as meby|eval snap=if(bytes>=meby, bytes, "smaller") |timechart count by snap

I just want a clarification whether my assumption is correct. My assumption being that meby will contain the median for all the values of bytes from the entire search. Is my assumption correct?

Tags (2)
0 Karma
1 Solution

Ayn
Legend

No, streamstats handles calculation of stats in a streaming manner (as is implied by the name). From the docs (http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Streamstats 😞

The streamstats command, similar to the stats command, calculates summary statistics on search results. Unlike, stats (which works on the results as a whole), streamstats calculates statistics for each event at the time the event is seen.

If you want to calculate stats on all search results, you'll want to use eventstats instead.

View solution in original post

Ayn
Legend

No, streamstats handles calculation of stats in a streaming manner (as is implied by the name). From the docs (http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Streamstats 😞

The streamstats command, similar to the stats command, calculates summary statistics on search results. Unlike, stats (which works on the results as a whole), streamstats calculates statistics for each event at the time the event is seen.

If you want to calculate stats on all search results, you'll want to use eventstats instead.

echalex
Builder

Great answer! Thanks!
The reason I needed the clarification was that my results with streamstats happened to coincide with the median of the entire result set. So in this case, the result looks identical to using eventstats, but some further testing highlights the differences.

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...