Splunk Search

timechart of running sum

jrstear
Path Finder

How to plot running sums? Eg given events with fields "time host errors", I'd like to do

  • | timechart accum(errors) by host

but timechart doesn't have accum, and accum doesn't have "by".

The below gets close:

  • | reverse | streamstats sum(errors) AS RunningSum by host window=10000 global=f | timechart sum(RunningSum) by host

but RunningSum sometimes decreases (which I don't understand or want), and there are definitely less than 10000 events so I don't think window size is the reason.

0 Karma

Stephen_Sorkin
Splunk Employee
Splunk Employee

This is somewhat tricky to do. Basically we first discretize time, like timechart does, so that we can calculate statistics per time bin. Then we count the errors in each time bin using stats. Next we use streamstats to achieve the accumulation. Last we use timechart to put it all together. A search like this should work:

... | bin _time | stats count as errors by _time host | streamstats sum(errors) as errors by series | timechart max(errors) by series

Jason
Motivator

The | bin _time | stats count didn't work for me. Instead I substituted it with another | timechart sum() and it worked fine.

0 Karma
Get Updates on the Splunk Community!

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...

Splunk APM: New Product Features + Community Office Hours Recap!

Howdy Splunk Community! Over the past few months, we’ve had a lot going on in the world of Splunk Application ...

Index This | Forward, I’m heavy; backward, I’m not. What am I?

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