MCPcopy Index your code
hub / github.com/prometheus/client_python / prometheus_app

Function prometheus_app

prometheus_client/exposition.py:134–161  ·  view source on GitHub ↗
(environ, start_response)

Source from the content-addressed store, hash-verified

132 """Create a WSGI app which serves the metrics from a registry."""
133
134 def prometheus_app(environ, start_response):
135 # Prepare parameters
136 accept_header = environ.get('HTTP_ACCEPT')
137 accept_encoding_header = environ.get('HTTP_ACCEPT_ENCODING')
138 params = parse_qs(environ.get('QUERY_STRING', ''))
139 method = environ['REQUEST_METHOD']
140
141 if method == 'OPTIONS':
142 status = '200 OK'
143 headers = [('Allow', 'OPTIONS,GET')]
144 output = b''
145 elif method != 'GET':
146 status = '405 Method Not Allowed'
147 headers = [('Allow', 'OPTIONS,GET')]
148 output = '# HTTP {}: {}; use OPTIONS or GET\n'.format(status, method).encode()
149 elif environ['PATH_INFO'] == '/favicon.ico':
150 # Serve empty response for browsers
151 status = '200 OK'
152 headers = []
153 output = b''
154 else:
155 # Note: For backwards compatibility, the URI path for GET is not
156 # constrained to the documented /metrics, but any path is allowed.
157 # Bake output
158 status, headers, output = _bake_output(registry, accept_header, accept_encoding_header, params, disable_compression)
159 # Return output
160 start_response(status, headers)
161 return [output]
162
163 return prometheus_app
164

Callers

nothing calls this directly

Calls 2

_bake_outputFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected