Release resources when Metricbeat stops

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

If a MetricSet implements 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.

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

@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.

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

Thanks for your hints ...

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

@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.

@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) 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.

1 Like

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

@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.

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