From 5c5d997ad5489376b2cdaa208ef11a26e64d6af4 Mon Sep 17 00:00:00 2001 From: Thomas Desrosiers Date: Thu, 9 Jun 2016 16:06:28 -0700 Subject: [PATCH] Adds support for the WSGI server to read from a different registry --- prometheus_client/exposition.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/prometheus_client/exposition.py b/prometheus_client/exposition.py index 5470ad7c..7e51ecec 100644 --- a/prometheus_client/exposition.py +++ b/prometheus_client/exposition.py @@ -28,21 +28,21 @@ '''Content type of the latest text format''' -def make_wsgi_app(): - '''Create a WSGI app which serves the metrics from the registry.''' +def make_wsgi_app(registry=core.REGISTRY): + '''Create a WSGI app which serves the metrics from a registry.''' def prometheus_app(environ, start_response): status = str('200 OK') headers = [(str('Content-type'), CONTENT_TYPE_LATEST)] start_response(status, headers) - return [generate_latest(core.REGISTRY)] + return [generate_latest(registry)] return prometheus_app -def start_wsgi_server(port, addr=''): +def start_wsgi_server(port, addr='', registry=core.REGISTRY): """Starts a WSGI server for prometheus metrics as a daemon thread.""" class PrometheusMetricsServer(threading.Thread): def run(self): - httpd = make_server(addr, port, make_wsgi_app()) + httpd = make_server(addr, port, make_wsgi_app(registry)) httpd.serve_forever() t = PrometheusMetricsServer() t.daemon = True