korfuri / django-prometheus

Export Django monitoring metrics for Prometheus.io
Apache License 2.0
1.44k stars 244 forks source link

Exporting /metrics in a WSGI application with multiple processes per process #423

Open boatcoder opened 5 months ago

boatcoder commented 5 months ago

I'm not sure how to read multiple processes per process. Is this supposed to be multiple threads per process?

nezumisama commented 4 weeks ago

Hi. I had the same issue. I solved it by adding code to gunicorn config file:

from prometheus_client import CollectorRegistry, multiprocess

def when_ready(_):
    multiprocess.MultiProcessCollector(CollectorRegistry())

def child_exit(_, worker):
    multiprocess.mark_process_dead(worker.pid)

Additionally, an environment variable PROMETHEUS_MULTIPROC_DIR has to be set to some empty dir. This is used to synchronize between workers.