Skip to content

Commit

Permalink
Support sending the OpenMetrics format when asked.
Browse files Browse the repository at this point in the history
Recent prometheus_client versions (v0.4.1 and later) support sending the
OpenMetrics format when clients negotiate for it via the HTTP Accept
header.
  • Loading branch information
atheriel committed Sep 2, 2020
1 parent 0b08ce4 commit d601696
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions prometheus_flask_exporter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from flask.views import MethodViewType
from werkzeug.serving import is_running_from_reloader
from prometheus_client import Counter, Histogram, Gauge, Summary
from prometheus_client import generate_latest, CONTENT_TYPE_LATEST
from prometheus_client.exposition import choose_encoder

if sys.version_info[0:2] >= (3, 4):
# Python v3.4+ has a built-in has __wrapped__ attribute
Expand Down Expand Up @@ -265,7 +265,8 @@ def prometheus_metrics():
if 'prometheus_multiproc_dir' in os.environ:
multiprocess.MultiProcessCollector(registry)

headers = {'Content-Type': CONTENT_TYPE_LATEST}
generate_latest, content_type = choose_encoder(request.headers.get("Accept"))
headers = {'Content-Type': content_type}
return generate_latest(registry), 200, headers

def start_http_server(self, port, host='0.0.0.0', endpoint='/metrics'):
Expand Down

0 comments on commit d601696

Please sign in to comment.