Skip to content
Merged
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
10 changes: 5 additions & 5 deletions prometheus_client/exposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down