From d4dd940d50993977f018c6c9e9e8c7634c7cfc49 Mon Sep 17 00:00:00 2001 From: Nicolas Ledez Date: Mon, 2 Oct 2023 16:48:57 +0200 Subject: [PATCH] Add prometheus /metrics --- setup.cfg | 1 + zou/app/__init__.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/setup.cfg b/setup.cfg index 2e31c788d2..93d3022c7e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -58,6 +58,7 @@ install_requires = OpenTimelineIO==0.15.0 orjson==3.9.7 pillow==10.0.1 + prometheus-flask-exporter==0.22.4 psutil==5.9.5 psycopg[binary]==3.1.12 pygelf==0.4.2 diff --git a/zou/app/__init__.py b/zou/app/__init__.py index 2dd2852471..9597bcc5a1 100644 --- a/zou/app/__init__.py +++ b/zou/app/__init__.py @@ -162,8 +162,24 @@ def add_permissions(_, payload): def load_api(): from zou.app import api + from zou import __version__ as zou_version api.configure(app) + try: + from prometheus_flask_exporter.multiprocess import ( + GunicornPrometheusMetrics, + ) + + metrics = GunicornPrometheusMetrics( + app, defaults_prefix="zou", group_by="url_rule" + ) + except ValueError: + from prometheus_flask_exporter import RESTfulPrometheusMetrics + + metrics = RESTfulPrometheusMetrics( + app, api, defaults_prefix="zou", group_by="url_rule" + ) + metrics.info("zou_info", "Application info", version=zou_version) fs.mkdir_p(app.config["TMP_DIR"]) configure_auth()