Skip to content

Commit

Permalink
Merge pull request rycus86#115 from apellini/add-https-to-dedicated-h…
Browse files Browse the repository at this point in the history
…ttp-server

adding ssl to dedicated http server
  • Loading branch information
rycus86 authored Dec 26, 2021
2 parents c9ff2b1 + 386918a commit 239a525
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions prometheus_flask_exporter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ def prometheus_metrics():
# apply the Flask route decorator on our metrics endpoint
app.route(path)(prometheus_metrics)

def start_http_server(self, port, host='0.0.0.0', endpoint='/metrics'):
def start_http_server(self, port, host='0.0.0.0', endpoint='/metrics', ssl=None):
"""
Start an HTTP server for exposing the metrics.
This will be an individual Flask application,
Expand All @@ -299,6 +299,9 @@ def start_http_server(self, port, host='0.0.0.0', endpoint='/metrics'):
:param host: the HTTP host to listen on (default: `0.0.0.0`)
:param endpoint: the URL path to expose the endpoint on
(default: `/metrics`)
:param ssl: enable SSL to http server.
It expects a dict with 2 keys cert and key with cert and key paths.
Default: None
"""

if is_running_from_reloader():
Expand All @@ -308,7 +311,10 @@ def start_http_server(self, port, host='0.0.0.0', endpoint='/metrics'):
self.register_endpoint(endpoint, app)

def run_app():
app.run(host=host, port=port)
if ssl is None:
app.run(host=host, port=port)
else:
app.run(host=host, port=port, ssl_context=(ssl["cert"], ssl["key"]))

thread = threading.Thread(target=run_app)
thread.daemon = True
Expand Down

0 comments on commit 239a525

Please sign in to comment.