run-as-root / magento2-prometheus-exporter

Simple Magento 2 Prometheus Exporter.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Prometheus Client PHP Library

Serializator opened this issue · comments

Parsing the metrics into a readable format for Prometheus shouldn't be the responsibility of the Magento module.

Prometheus has a link to a PHP library that handles the parsing of metrics into a readable format for Prometheus to interpret.

Prometheus Client Libraries
"Prometheus Client PHP" by Jimbo

Moving this responsibility to a separate library reduces the overall code complexity of the module itself, and most likely also reduces bugs because of the Prometheus Client PHP library being well tested by many developers.

We had a look at the PHP Client Library and decided not to use it. I just had another look into the lib. When I'm correct, we'd only use the render function. I sit between the chairs xD. On the one hand, you're totally right and using the lib might give us more stability. On the other hand, the metrics endpoint format is quite simple.

@mwr any opinions?

@DavidLambauer, you'd also use the metric collectors to keep track of the metrics, this would replace the existing table and make the metric models, resource models, collections and repositories obsolete.

Prometheus Client PHP also gives various ways of keeping the state of the metrics by using Redis, APC or in-memory. Because most of the current aggregators use gauge metrics, keeping these in a table, permanently stored, is a bit of an overhead if you think about it.

If you're interested in kind of a prototype, I wrote a quick implementation of the Prometheus Client PHP library by Jomda in the past two evenings.

https://github.com/Serializator/magento2-prometheus-exporter/tree/prometheus-php-library

Obviously some edge-case is missing, such as error handling for when the Redis or APCu extensions aren't loaded, maybe an indication in the configuration when this is the case, those kinda things.

Hi @Serializator, just talked to @mwr about your recommendation. We'd like to follow your request to implement the given SDK. We think that most Magento 2 Installations make use of redis (at least they should 😄), so it totally makes sense to store the metrics in redis. Therefore we can drop some unnecessary code.

I had a look at your prototype. How would you like to proceed with it? Would you prefer to finish the prototype?

Hi @DavidLambauer, I wrote the prototype with the mindset "it's only a prototype". If I'd proceed with it, it would help a lot to get some feedback from you guys so that I can improve upon design decisions I made or even rewrite them.

Regardless of the "it's only a prototype", feedback is always a good thing of course 😜

Hey @Serializator, I just added you to the repo. Feel free to open a new branch with your prototype. I also send you a slack invitation to get more into the details.