Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(exports): use try except to handle port in use by django gunicorn #407

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion django_prometheus/exports.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down