hynek / prometheus-async

Async Python helpers for the official prometheus-client.
https://prometheus-async.readthedocs.io/
Apache License 2.0
159 stars 15 forks source link

Support for multiple gunicorn workers. #16

Closed aamikus closed 9 months ago

aamikus commented 4 years ago

The official python Prometheus client outlines a problem caused by using multiple Gunicorn workers and provides a solution: https://github.com/prometheus/client_python/#multiprocess-mode-gunicorn

I am working on an asynchronous web-app using FastAPI with 4 Gunicorn workers, therefore I cannot use the synchronous Prometheus client. However, this library has no mention of dealing with the multiprocessing issue, and after running some tests, has no built-in solution to deal with it. My question is, is there any plan to add support for multiprocessing? If not, what solution would you recommend? I would prefer to continue using the pull model.

Thank You.

hynek commented 4 years ago

If your app is async, you can start separate web servers per process. This is actually much better than the sync approach, because it will expose all metrics – including memory.

ptrometheus-async comes with first class support to do that for you with aiohttp but it shouldn't be too hard to adapt to FastAPI? If haven't used it so far myself.

P.S. Sorry for the long delay, I have some thoughts about building something better but just couldn't get around working on it.