From d38777318ecd1d5e7d7632a3e1d28fc667aa2192 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20Pfl=C3=BCgner?= Date: Wed, 23 Sep 2026 12:36:29 +0200 Subject: [PATCH] feat: add optional Prometheus metrics endpoint --- config.py.example | 4 ++++ lufa/__init__.py | 7 +++++++ requirements.txt | 1 + 3 files changed, 12 insertions(+) diff --git a/config.py.example b/config.py.example index ac64600..8f8ca6a 100644 --- a/config.py.example +++ b/config.py.example @@ -52,3 +52,7 @@ #LOGIN_USERNAME_LABEL = "Username" #LOGIN_PASSWORD_LABEL = "Password" #LOGIN_SUBMIT_LABEL = "Sign in" + +### Metrics (optional) +# Enable Prometheus metrics endpoint at /metrics +#ENABLE_METRICS_ENDPOINT=True diff --git a/lufa/__init__.py b/lufa/__init__.py index e079a7d..7e548e5 100644 --- a/lufa/__init__.py +++ b/lufa/__init__.py @@ -115,6 +115,13 @@ def set_security_headers(response): csrf.exempt(api_v1.bp) app.register_blueprint(frontend.bp) + # Prometheus metrics + if app.config.get("ENABLE_METRICS_ENDPOINT", False): + from prometheus_flask_exporter import PrometheusMetrics + + PrometheusMetrics(app, prefix="lufa") + app.logger.info("Prometheus metrics enabled at /metrics") + login_manager = LoginManager(app) if str(app.config.get("AUTH")).upper().startswith("LOCAL"): user_manager = UserManager(app) diff --git a/requirements.txt b/requirements.txt index 949c4f6..ec2fd0c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,7 @@ Flask==3.1.3 flask-ldap3-login==1.0.2 Flask-Login==0.6.3 +prometheus-flask-exporter==0.23.2 psycopg2-binary==2.9.11 uWSGI==2.0.31 requests==2.32.5