From 8c20057a429b7c3813baae53356a0dffe9493210 Mon Sep 17 00:00:00 2001 From: Jelle van der Waa Date: Mon, 22 Jul 2024 21:30:28 +0200 Subject: [PATCH] Add support for exporting prometheus metrics --- requirements.txt | 1 + settings.py | 8 ++++++++ urls.py | 6 ++++++ 3 files changed, 15 insertions(+) diff --git a/requirements.txt b/requirements.txt index a660bb18..5c91ecd7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -16,3 +16,4 @@ bleach==6.0.0 requests==2.32.0 xtarfile==0.1.0 zstandard==0.17.0 +django-prometheus==2.3.1 diff --git a/settings.py b/settings.py index 4833efb8..7b12204b 100644 --- a/settings.py +++ b/settings.py @@ -6,6 +6,9 @@ DEBUG = False DEBUG_TOOLBAR = False +# Export prometheus metrics +PROMETHEUS_METRICS = False + # Notification admins ADMINS = () @@ -265,4 +268,9 @@ INSTALLED_APPS = [*list(INSTALLED_APPS), 'debug_toolbar'] +if PROMETHEUS_METRICS: + MIDDLEWARE = ['django_prometheus.middleware.PrometheusBeforeMiddleware', *list(MIDDLEWARE), 'django_prometheus.middleware.PrometheusAfterMiddleware'] + + INSTALLED_APPS = [*list(INSTALLED_APPS), 'django_prometheus'] + # vim: set ts=4 sw=4 et: diff --git a/urls.py b/urls.py index fa983715..3ba7043f 100644 --- a/urls.py +++ b/urls.py @@ -114,6 +114,12 @@ path('__debug__/', include(debug_toolbar.urls)), ]) +# prometheus metrics +if settings.PROMETHEUS_METRICS: # pragma :no cover + urlpatterns.extend([ + path('', include('django_prometheus.urls')), + ]) + # displays all archweb urls def show_urls(urllist=urlpatterns, depth=0): # pragma: no cover