Splunk Search

How do you use the streamstats command after tstats and stats?

akocak
Contributor

Hi,

Thanks upfront for your time. I need to aggregate some information with the tstats command and make a weekly comparative analysis.
The search I created is working if i pick parameters, however, it doesn't if I don't give any parameters due to nature of |streamstats.

| tstats avg(elapsed) as avgElapsed where host="A"  index="X" sourcetype="Y" ID="Z" by _time, host,ID span=1week 
| eval myval = host."-".ID 
| stats sum(count) as count latest(avgElapsed) as avgElapsed by _time,myval 
| streamstats current=f window=1 latest(avgElapsed) as prev_elapsed

Logically, I would expect adding "by" clause to the streamstats command should get me what I need. However, it is not returning results for previous weeks when I do that. It only works on a row by row basis, which points to another ID or host in the data sometimes:

    | streamstats current=f window=1 latest(avgElapsed) as prev_elapsed by myval

Please help me out. Kind regards

0 Karma
1 Solution

somesoni2
Revered Legend

Give this a try

| tstats avg(elapsed) as avgElapsed where host="A"  index="X" sourcetype="Y" ID="Z" by _time, host,ID span=1week 
 | eval myval = host."-".ID 
 | stats sum(count) as count latest(avgElapsed) as avgElapsed by myval _time
 | streamstats current=f window=1 latest(avgElapsed) as prev_elapsed by myval

View solution in original post

0 Karma

somesoni2
Revered Legend

Give this a try

| tstats avg(elapsed) as avgElapsed where host="A"  index="X" sourcetype="Y" ID="Z" by _time, host,ID span=1week 
 | eval myval = host."-".ID 
 | stats sum(count) as count latest(avgElapsed) as avgElapsed by myval _time
 | streamstats current=f window=1 latest(avgElapsed) as prev_elapsed by myval
0 Karma

renjith_nair
Legend

@akocak,

Sorry if mistaken but if you are trying to bring value from previous row to current row, then try using last instead of latest in streamstats.

Happy Splunking!
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 ...