artprima / prometheus-metrics-bundle

Symfony 5/6 Prometheus Metrics Bundle
MIT License
128 stars 29 forks source link

Collection registry access #12

Closed xdrew closed 4 years ago

xdrew commented 4 years ago

Hello!

Is it possible to somehow get access to collectionRegistry in my code without implementing MetricsGeneratorInterface? My metrics do not depend on requests/responses. They come from commands running as daemons. Once something happens, I just want to update my counters, gauges in that registry, but it doesn't seem to be accessible via DI. Any ideas?

Thanks in advance.

denisvmedia commented 4 years ago

Well, you may use prometheus_metrics_bundle.collector_registry service via DI and write the metrics directly. Is there any problem with using the registry service?

xdrew commented 4 years ago

Yep.

 The service "App\Utils\MetricUtils" has a dependency on a non-existent service "prometheus_metrics_bundle.collector_registry".

Do I need to decorate it or create a similar compiler pass?

denisvmedia commented 4 years ago

I think, for it to work you should have your command as a service. Here you can find a similar issue with more details: https://github.com/FriendsOfSymfony/FOSElasticaBundle/issues/1271