# How to clear counter without loss?

**URL:** https://discuss.elastic.co/t/how-to-clear-counter-without-loss/2034
**Category:** Logstash
**Created:** [June 5, 2015, 6:05pm UTC](https://discuss.elastic.co/t/how-to-clear-counter-without-loss/2034 "2015-06-05T18:05:11Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![kelvinfann](https://avatars.discourse-cdn.com/v4/letter/k/13edae/32.png) [@kelvinfann](https://discuss.elastic.co/u/kelvinfann)
#### Post date: [June 5, 2015, 6:05pm UTC](https://discuss.elastic.co/t/how-to-clear-counter-without-loss/2034/1 "2015-06-05T18:05:11Z")

</div>

Hi!  
I am relatively new to log stash, so forgive my ignorance.

I am trying to count the throughput of logs in log stash for a fixed amount sets of time ('.count'). Naturally, therefore, I have been trying the filter 'metric', with:

- meter =\> "message"
- add\_tag =\> "metric"
- periodic\_flush =\> true
- flush\_interval =\> 10
- clear\_interval =\> 10

The problem with this is that log stash clears before it flushes, which results in no data output. I could have a difference in time between flush and clear, but that opens the room for messages coming in-between the flush and clear time, which would result in a miscount, which I cannot afford.

What I need to be able to do is assign the metric to be flushed and then immediately cleared sequentially, without other messages going through between the flush and clear so I can get an accurate count of the messages sent through in the past X seconds (every X seconds) and pass that through as a separate log. Is that possible?

---

<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: [July 6, 2017, 5:38am UTC](https://discuss.elastic.co/t/how-to-clear-counter-without-loss/2034/2 "2017-07-06T05:38:23Z")

</div>


