# Last run of metricbeat module

**URL:** <https://discuss.elastic.co/t/last-run-of-metricbeat-module/99114>\
**Category:** Beats\
**Tags:** metricbeat\
**Created:** [September 1, 2017, 10:41am UTC](https://discuss.elastic.co/t/last-run-of-metricbeat-module/99114 "2017-09-01T10:41:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniel\_DNP](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/daniel_dnp/32/16374_2.png) [@Daniel\_DNP](https://discuss.elastic.co/u/Daniel_DNP)\
**Post date:** [September 1, 2017, 10:41am UTC](https://discuss.elastic.co/t/last-run-of-metricbeat-module/99114/1 "2017-09-01T10:41:29Z")

</div>

Hello!

I'm developing a metricbeat module for a database. I would like to fetch backup information from the database. I don't want to fetch all backup information each time the module runs. Just the information which is new.

Is there a way to get the configured interval of the metricbeat module?

Thank you!

---

<div class="post-metadata">

**Author:** ![andrewkroh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrewkroh/32/3784_2.png) [@andrewkroh](https://discuss.elastic.co/u/andrewkroh)\
**Post date:** [September 1, 2017, 7:57pm UTC](https://discuss.elastic.co/t/last-run-of-metricbeat-module/99114/2 "2017-09-01T19:57:23Z")

</div>

The configured `period` is available to the metricset through the [ModuleConfig](https://godoc.org/github.com/elastic/beats/metricbeat/mb#BaseModule.Config) (e.g. `ms.Module().Config().Period`).

You could store in memory the time of the last fetch and use that in your query so that you fetch only information newer than that last fetch time.

---

<div class="post-metadata">

**Author:** ![Daniel\_DNP](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/daniel_dnp/32/16374_2.png) [@Daniel\_DNP](https://discuss.elastic.co/u/Daniel_DNP)\
**Post date:** [September 4, 2017, 9:58am UTC](https://discuss.elastic.co/t/last-run-of-metricbeat-module/99114/3 "2017-09-04T09:58:55Z")

</div>

Thank you!  
I was already thinking of storing the last execution time in a variable. But when my module was down for some time and it comes up again I would miss the last backup(s) because they are older than the `now - period`.

This would not be a big deal. The only problem is that a false alert like "backup missing" would be cleared after up to 24h.

To avoid this situation I'll code something like this: If the module comes up and `lastExec` is nil then I fetch the latest backup. Else, fetch backups which are newer then `now - period`.

---

<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:** [October 2, 2017, 9:59am UTC](https://discuss.elastic.co/t/last-run-of-metricbeat-module/99114/4 "2017-10-02T09:59:03Z")

</div>

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