# Release resources when Metricbeat stops

**URL:** <https://discuss.elastic.co/t/release-resources-when-metricbeat-stops/107542>\
**Category:** Beats\
**Tags:** metricbeat\
**Created:** [November 14, 2017, 11:39am UTC](https://discuss.elastic.co/t/release-resources-when-metricbeat-stops/107542 "2017-11-14T11:39:47Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![mguggi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mguggi/32/79070_2.png) [@mguggi](https://discuss.elastic.co/u/mguggi)\
**Post date:** [November 14, 2017, 11:39am UTC](https://discuss.elastic.co/t/release-resources-when-metricbeat-stops/107542/1 "2017-11-14T11:39:47Z")

</div>

Hi,

I'm new in go and metricbeat. I want write a metricbeat module which collects data from an Oracle database. Unfortunately I found no function (or way) to cleanup my connection when metricbeat will be stopped.

I also looked at the mysql module. But unfortunately I can't find anything in this code where the connection will be closed.

Is there a way I can do that? A shutdown hook, override a method or function or something else ...

Best Regards

---

<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:** [November 14, 2017, 6:58pm UTC](https://discuss.elastic.co/t/release-resources-when-metricbeat-stops/107542/2 "2017-11-14T18:58:49Z")

</div>

If a `MetricSet` implements [`Closer`](https://godoc.org/github.com/elastic/beats/metricbeat/mb#Closer) then `Close()` will be called when the `MetricSet` is stopped.

> Closer is an optional interface that a MetricSet can implement in order to cleanup any resources it has open at shutdown.

---

<div class="post-metadata">

**Author:** ![mguggi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mguggi/32/79070_2.png) [@mguggi](https://discuss.elastic.co/u/mguggi)\
**Post date:** [November 15, 2017, 12:19am UTC](https://discuss.elastic.co/t/release-resources-when-metricbeat-stops/107542/3 "2017-11-15T00:19:50Z")

</div>

Thank you for the advice. I have tried to implement the following:

```
// Closer is an optional interface that a MetricSet can implement in order to
// cleanup any resources it has open at shutdown.
func (m *MetricSet) Close() error {
    logp.Info(" ***********************cleanup stuff******************")
    return nil
}

```

Then I build the beat and run it with the command below:

```
./oraclebeat -e -d "*" -N

```

After some time I cancel the beat with Ctrl + C.

Unfortunately I'm not able to find the log entry in the output.

Have you any hint for me or an idea what is going wrong?

Regards

---

<div class="post-metadata">

**Author:** ![ruflin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ruflin/32/3116_2.png) [@ruflin](https://discuss.elastic.co/u/ruflin)\
**Post date:** [November 15, 2017, 2:16am UTC](https://discuss.elastic.co/t/release-resources-when-metricbeat-stops/107542/4 "2017-11-15T02:16:04Z")

</div>

@mguggi Could you share a link to the repo (if possible)? That would it make easier to see what the error could be as the full code is visible.

---

<div class="post-metadata">

**Author:** ![mguggi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mguggi/32/79070_2.png) [@mguggi](https://discuss.elastic.co/u/mguggi)\
**Post date:** [November 15, 2017, 7:15pm UTC](https://discuss.elastic.co/t/release-resources-when-metricbeat-stops/107542/5 "2017-11-15T19:15:55Z")

</div>

After upgrading from metricbeat 5.6.5 to 6.0.1 it works as expected. I haven't spent much time to analyze the root cause.

Maybe it's a bug maybe I have done something wrong. However I haven't changed the implementation of the Close method.

@ruflin The example code is shared on github: [oraclebeat](https://github.com/mguggi/oraclebeat.git)

Thanks for your hints ...

---

<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:** [November 15, 2017, 7:49pm UTC](https://discuss.elastic.co/t/release-resources-when-metricbeat-stops/107542/6 "2017-11-15T19:49:40Z")

</div>

I think the `Closer` feature was only added to 6.0+.

---

<div class="post-metadata">

**Author:** ![ruflin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ruflin/32/3116_2.png) [@ruflin](https://discuss.elastic.co/u/ruflin)\
**Post date:** [November 16, 2017, 2:45am UTC](https://discuss.elastic.co/t/release-resources-when-metricbeat-stops/107542/7 "2017-11-16T02:45:14Z")

</div>

@mguggi Glad you got it working. What are your plans with oracle module? I'm thinking if we should have something like this in Metricbeat itself in the future. Starting as you did is great as it makes it very easy to do some iterations on it.

---

<div class="post-metadata">

**Author:** ![mguggi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mguggi/32/79070_2.png) [@mguggi](https://discuss.elastic.co/u/mguggi)\
**Post date:** [November 16, 2017, 9:40am UTC](https://discuss.elastic.co/t/release-resources-when-metricbeat-stops/107542/8 "2017-11-16T09:40:23Z")

</div>

@ruflin I'm working as an Oracle DBA and I want create a way for users to monitor Oracle without Oracle Cloud Control and such stuff. I think the elastic stack is a great solution for this plan if that stack is already used for log aggregation in the project anyway.

In the first version I want snapshot the current sessions on an Oracle database and store this in elasticsearch. This feature ([Active Session History](http://www.oracle.com/technetwork/issue-archive/2013/13-jan/o13dba-1871177.html)) already exists for an Oracle Enterprise Edition, but unfortunately with additional license costs.

My main goal is to monitor crucial metrics such as cpu usage, memory usage (SGA, PGA), disk usage, active session history etc. (a few metricsets like in the system module) with this module and also provide a kibana dashboard to visualize the collected data.

In my opinion, it would be great if we could integrate the oracle module into metricbeat at the appropriate time.

---

<div class="post-metadata">

**Author:** ![steffens](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/steffens/32/79630_2.png) [@steffens](https://discuss.elastic.co/u/steffens)\
**Post date:** [November 16, 2017, 1:50pm UTC](https://discuss.elastic.co/t/release-resources-when-metricbeat-stops/107542/9 "2017-11-16T13:50:05Z")

</div>

Oracle module in metricbeat might be a little tricky. Problem is the dynamic linking against the oracle shared libs required by the SQL driver. This would force every metricbeat user to have these dependencies installed.

I have an POC on how cgo + late library loading can be implemented, but no windows support yet: [https://github.com/urso/hellocurses](https://github.com/urso/hellocurses)

---

<div class="post-metadata">

**Author:** ![ruflin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ruflin/32/3116_2.png) [@ruflin](https://discuss.elastic.co/u/ruflin)\
**Post date:** [November 16, 2017, 10:50pm UTC](https://discuss.elastic.co/t/release-resources-when-metricbeat-stops/107542/10 "2017-11-16T22:50:30Z")

</div>

@mguggi Feel free to ping us if you hit any issue or if you have a first version running. I'm curious how the code will look like.

---

<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 14, 2017, 10:50pm UTC](https://discuss.elastic.co/t/release-resources-when-metricbeat-stops/107542/11 "2017-12-14T22:50:48Z")

</div>

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