galexrt / dellhw_exporter

Prometheus exporter for Dell Hardware components using Dell OMSA.
https://dellhw-exporter.galexrt.moe
Apache License 2.0
119 stars 41 forks source link

Implement configurable caching #46

Closed Phil1602 closed 4 years ago

Phil1602 commented 4 years ago

Hi,

thanks for this exporter.

We have many Promethei, which are scraping in parallel with a small scrape interval. Unfortunately we discovered load issues because of the DellHW Exporter respectively the expensive underlying omreport calls (all collectors were enabled) on our machines.

We decided to implement a simple in memory cache, which can be enabled using the configuration flags, to face this problem. The caching is optional and can be enabled using the configuration parameters.

Implementation details: I decided to implement an additional adapter channel, which will be used to retrieve the collected metrics and put them into an array if caching is enabled. A mutex is used to prevent concurrent collections and concurrent write operations to the cache.

Since the metrics are written into a "local" channel instead of the channel passed by the Prometheus library directly, we need a second waitgroup. The first waitgroup ensures that all collectors have finished. The second waitgroup ensures that all metrics are written to the outgoing channel before the method returns. This is needed because the Prometheus library will close the channel once the method returns.

There was already a field for the last collection timestamp, which was not actually used before. The initial timestamp will now be Unix 0 instead of the current time (start time of the exporter), because otherwise the actual collection would not be executed within the first cache period if caching is enabled. Also the receiver had to be changed to Pointer instead of Value, because the updated timestamp was only updated for the copy in case of the value receiver.

The new configuration parameters have been added to the configuration documentation. Shall I add some more documentation to further describe the caching behavior for the end user? What about the debug logs, are they ok or shall I remove them?

Thanks! Philipp

Phil1602 commented 4 years ago

I will add the documentation page tomorrow.

Phil1602 commented 4 years ago

Sorry I didn't had time yesterday. The documention has been added.

Phil1602 commented 4 years ago

Applied your suggestions and squashed the documentation related commits together.

galexrt commented 4 years ago

@Phil1602 Thanks for the PR and quick updates!

I'll push a new release in a few hours after the merge.

galexrt commented 4 years ago

@Phil1602 v1.7.0 has been released.