diff --git a/django_prometheus/exports.py b/django_prometheus/exports.py index 94c04156..bf63f59d 100644 --- a/django_prometheus/exports.py +++ b/django_prometheus/exports.py @@ -42,7 +42,16 @@ def SetupPrometheusEndpointOnPort(port, addr=""): "autoreloader is active. Use the URL exporter, or start django " "with --noreload. See documentation/exports.md." ) - prometheus_client.start_http_server(port, addr=addr) + + registry = prometheus_client.CollectorRegistry() + multiprocess.MultiProcessCollector(registry) + try: + prometheus_client.start_http_server(port, addr=addr, registry=registry) + except OSError: + """ + first process serves metrics on port 8001, other processes raise error: port already in use + one processes collect metrics from PROMETHEUS_MULTIPROC_DIR + """ class PrometheusEndpointServer(threading.Thread):