# Non-negative Serial Diff for a "counter" that resets to 0 from time to time

**URL:** <https://discuss.elastic.co/t/non-negative-serial-diff-for-a-counter-that-resets-to-0-from-time-to-time/256046>\
**Category:** Kibana\
**Created:** [November 19, 2020, 10:15pm UTC](https://discuss.elastic.co/t/non-negative-serial-diff-for-a-counter-that-resets-to-0-from-time-to-time/256046 "2020-11-19T22:15:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mludvig](https://avatars.discourse-cdn.com/v4/letter/m/3ec8ea/32.png) [@mludvig](https://discuss.elastic.co/u/mludvig)\
**Post date:** [November 19, 2020, 10:15pm UTC](https://discuss.elastic.co/t/non-negative-serial-diff-for-a-counter-that-resets-to-0-from-time-to-time/256046/1 "2020-11-19T22:15:23Z")

</div>

I'm collecting stats from some industrial process that has variable number of `workers` that produce some output at a variable rate, that is accumulating to a `balance` queue that from time to time is flushed and reset to 0.

I'm trying to visualise the rate of change in the queue, ie how much have the workers produced in the given period of time. It should be reasonably simple with `serialDiff` aggregator, however flushing the output queue throws the stats off as it always produces a massive negative spike. How can I overcome that? I would like to have something like `nonNegativeSerialDiff` similar to what _InfluxDB_ has.

I want to get rid of the massive red negative spikes. When that happens the counter was reset to 0 so the next diff point should be the actual balance on blue line (e.g. 50 or so).

 ![Screenshot_514_Selection](https://us1.discourse-cdn.com/elastic/original/3X/e/7/e793887470f41193c21601174d6bc93a6612da8a.png)

If anyone is interested the sample data is here: [https://pastebin.com/4wNs8YvK](https://pastebin.com/4wNs8YvK) (note that I have added `output` column to the data set that's the value that I ultimately want to display, but I don't have it in the actual source data, it's only there for reference).

Thanks!

---

<div class="post-metadata">

**Author:** ![wylie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wylie/32/81794_2.png) [@wylie](https://discuss.elastic.co/u/wylie)\
**Post date:** [November 19, 2020, 10:33pm UTC](https://discuss.elastic.co/t/non-negative-serial-diff-for-a-counter-that-resets-to-0-from-time-to-time/256046/2 "2020-11-19T22:33:32Z")

</div>

This is actually an existing feature of the TSVB visualization type. There is a shortcut called "counter rate" or "positive rate" depending on your version (we just renamed it). You can also do the same by doing a "Positive only" function in TSVB

---

<div class="post-metadata">

**Author:** ![mludvig](https://avatars.discourse-cdn.com/v4/letter/m/3ec8ea/32.png) [@mludvig](https://discuss.elastic.co/u/mludvig)\
**Post date:** [November 19, 2020, 11:35pm UTC](https://discuss.elastic.co/t/non-negative-serial-diff-for-a-counter-that-resets-to-0-from-time-to-time/256046/3 "2020-11-19T23:35:48Z")

</div>

That's exactly what I need, thanks!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 17, 2020, 11:35pm UTC](https://discuss.elastic.co/t/non-negative-serial-diff-for-a-counter-that-resets-to-0-from-time-to-time/256046/4 "2020-12-17T23:35:53Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
