Splunk Enterprise

streamstats and delta

tb5821
Communicator

My search brings back data in a table like so:

_time|product|count
8/15/15 08:00:00|apples|500
8/15/15 08:00:00|oranges|800
8/15/15 08:00:00|plums|200
8/15/15 08:00:00|peaches|275

What I want is to have splunk compute the diff between the latest value above and the one just before it per product. So it ends up like:

8/15/15 08:00:00|apples|500|+50
8/15/15 08:00:00|oranges|800|+200
8/15/15 08:00:00|plums|200|-2
8/15/15 08:00:00|peaches|275|+80

Pretty sure I need to use streamstats and delta but can't get the combo right.

1 Solution

kmaron
Motivator

it sounds like your question is like this one: https://answers.splunk.com/answers/329534/how-to-determine-the-delta-between-events-based-on.html

So based on that answer you could try this:

 | streamstats current=f last(count) as last_count by product
 | rename count as current_count
 | eval delta = last_count - current_count
 | table _time product current_count delta

View solution in original post

kmaron
Motivator

it sounds like your question is like this one: https://answers.splunk.com/answers/329534/how-to-determine-the-delta-between-events-based-on.html

So based on that answer you could try this:

 | streamstats current=f last(count) as last_count by product
 | rename count as current_count
 | eval delta = last_count - current_count
 | table _time product current_count delta
Get Updates on the Splunk Community!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

Splunk is officially part of Cisco

Revolutionizing how our customers build resilience across their entire digital footprint.   Splunk ...

Splunk APM & RUM | Planned Maintenance March 26 - March 28, 2024

There will be planned maintenance for Splunk APM and RUM between March 26, 2024 and March 28, 2024 as ...