Skip to content

Commit

Permalink
back to GunicornPrometheusMetrics, CollectoRegistry, port 9200
Browse files Browse the repository at this point in the history
  • Loading branch information
charlienegri committed Oct 8, 2024
1 parent a79acd8 commit 2ab6a19
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
6 changes: 5 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ ENTRYPOINT ["dumb-init", "--"]

ENV PROMETHEUS_MULTIPROC_DIR /tmp
ENV prometheus_multiproc_dir /tmp
ENV METRICS_PORT 9200
EXPOSE 9200

COPY container/gunicorn_prometheus_config.py /src/

# Start application
CMD gunicorn --worker-class sync --workers 5 --bind 0.0.0.0:8000 wsgi:app --keep-alive 5 --log-level info
CMD gunicorn -c /src/gunicorn_prometheus_config.py --worker-class sync --workers 5 --bind 0.0.0.0:8000 wsgi:app --keep-alive 5 --log-level info
11 changes: 11 additions & 0 deletions container/gunicorn_prometheus_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import os

from prometheus_flask_exporter.multiprocess import GunicornPrometheusMetrics


def when_ready(server):
GunicornPrometheusMetrics.start_http_server_when_ready(int(os.getenv('METRICS_PORT')))


def child_exit(server, worker):
GunicornPrometheusMetrics.mark_process_dead_on_child_exit(worker.pid)
6 changes: 3 additions & 3 deletions container/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import os
import sys

from prometheus_flask_exporter.multiprocess import GunicornInternalPrometheusMetrics
from prometheus_flask_exporter.multiprocess import GunicornPrometheusMetrics
from werkzeug.middleware.dispatcher import DispatcherMiddleware
from prometheus_client import make_wsgi_app, CollectorRegistry
from prometheus_client.core import REGISTRY
Expand All @@ -35,6 +35,6 @@
app = App()
REGISTRY.register(CollectorRegistry())
app.wsgi_app = DispatcherMiddleware(app.wsgi_app, {
'/metrics': make_wsgi_app(REGISTRY)
'/metrics': make_wsgi_app(registry=REGISTRY)
})
GunicornInternalPrometheusMetrics(app, path='/metrics', registry=REGISTRY)
GunicornPrometheusMetrics(app, path='/metrics', registry=REGISTRY)

0 comments on commit 2ab6a19

Please sign in to comment.