-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Flask: add Prometheus endpoint (#983)
This is to help gain insights for #950. Leverage [prometheus-flask-exporter](https://github.com/rycus86/prometheus_flask_exporter), a high-level client atop Prometheus' Python client designed for Flask and Gunicorn. Use `/tmp` for the multiprocess directory to temporarily write metrics for the manager process, which is always writable and reset when the container is recreated, as required. Add alternate gunicorn configuration for testing this metrics setup without going straight into production. Integrate entrypoints into Dockerfile, now that stager-dev is no longer needed. Disable pip cache when building images to reduce image size.
- Loading branch information
Showing
11 changed files
with
105 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,22 @@ | ||
from os import getenv | ||
from flask_login import LoginManager | ||
from flask_marshmallow import Marshmallow | ||
from flask_migrate import Migrate | ||
from flask_sqlalchemy import SQLAlchemy | ||
from authlib.integrations.flask_client import OAuth | ||
from prometheus_flask_exporter import PrometheusMetrics | ||
from prometheus_flask_exporter.multiprocess import GunicornPrometheusMetrics | ||
|
||
db = SQLAlchemy() | ||
login = LoginManager() | ||
migrate = Migrate(compare_type=True) | ||
oauth = OAuth() | ||
ma = Marshmallow() | ||
login.session_protection = "strong" | ||
|
||
if getenv("FLASK_ENV") == "development": | ||
# Note that /metrics will not be live without DEBUG_METRICS set | ||
metrics = PrometheusMetrics(None) | ||
else: # production | ||
# Must additionally set PROMETHEUS_MULTIPROC_DIR | ||
metrics = GunicornPrometheusMetrics(None, path=None) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from prometheus_flask_exporter.multiprocess import GunicornPrometheusMetrics | ||
|
||
|
||
def when_ready(server): | ||
GunicornPrometheusMetrics.start_http_server_when_ready(8080) | ||
|
||
|
||
def child_exit(server, worker): | ||
GunicornPrometheusMetrics.mark_process_dead_on_child_exit(worker.pid) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,16 @@ | ||
apscheduler | ||
authlib | ||
flask | ||
flask_sqlalchemy | ||
flask_login | ||
flask-marshmallow | ||
flask_migrate | ||
flask_sqlalchemy | ||
gunicorn | ||
marshmallow-sqlalchemy | ||
minio | ||
pandas | ||
prometheus-flask-exporter | ||
pymysql[rsa] | ||
requests | ||
sendgrid | ||
sqlalchemy | ||
flask-marshmallow | ||
marshmallow-sqlalchemy | ||
sendgrid |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters