Skip to content

Commit

Permalink
Export prometheus metrics (#1685)
Browse files Browse the repository at this point in the history
Export prometheus metrics
  • Loading branch information
rolandgeider authored May 30, 2024
1 parent 6154347 commit cdf84d1
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
6 changes: 6 additions & 0 deletions extras/docker/development/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,9 @@
#
CELERY_BROKER_URL = env.str("CELERY_BROKER", "redis://cache:6379/2")
CELERY_RESULT_BACKEND = env.str("CELERY_BACKEND", "redis://cache:6379/2")

#
# Prometheus metrics
#
EXPOSE_PROMETHEUS_METRICS = env.bool('EXPOSE_PROMETHEUS_METRICS', False)
PROMETHEUS_URL_PATH = env.str('PROMETHEUS_URL_PATH', 'super-secret-path')
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ django-crispy-forms~=2.1
django-email-verification~=0.3.3
django-environ==0.11.2
django-formtools~=2.5
django-prometheus==2.3.1
django-recaptcha~=4.0.0
django-simple-history~=3.5
django-storages~=1.14
Expand Down
24 changes: 19 additions & 5 deletions wger/settings_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
from wger import get_version
from wger.utils.constants import DOWNLOAD_INGREDIENT_WGER


"""
This file contains the global settings that don't usually need to be changed.
For a full list of options, visit:
Expand All @@ -41,7 +40,7 @@
ROOT_URLCONF = 'wger.urls'
WSGI_APPLICATION = 'wger.wsgi.application'

INSTALLED_APPS = (
INSTALLED_APPS = [
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.messages',
Expand Down Expand Up @@ -112,9 +111,15 @@

# Fontawesome
'fontawesomefree',
)

MIDDLEWARE = (
# Prometheus
'django_prometheus',
]

MIDDLEWARE = [
# Prometheus
'django_prometheus.middleware.PrometheusBeforeMiddleware',

'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
Expand All @@ -138,9 +143,12 @@
# History keeping
'simple_history.middleware.HistoryRequestMiddleware',

# Prometheus
'django_prometheus.middleware.PrometheusAfterMiddleware',

# Django Axes
'axes.middleware.AxesMiddleware', # should be the last one in the list
)
]

AUTHENTICATION_BACKENDS = (
'axes.backends.AxesStandaloneBackend', # should be the first one in the list
Expand Down Expand Up @@ -544,6 +552,12 @@
'WGER_INSTANCE': 'https://wger.de',
}

#
# Prometheus metrics
#
EXPOSE_PROMETHEUS_METRICS = False
PROMETHEUS_URL_PATH = 'super-secret-path'


#
# Django email verification
Expand Down
6 changes: 5 additions & 1 deletion wger/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
from wger.utils.generic_views import TextTemplateView
from wger.weight.api import views as weight_api_views


#
# REST API
#
Expand Down Expand Up @@ -300,3 +299,8 @@
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
# urlpatterns.append(path("__debug__/", include("debug_toolbar.urls")))

if settings.EXPOSE_PROMETHEUS_METRICS:
urlpatterns += [
path(f'prometheus/{settings.PROMETHEUS_URL_PATH}/', include('django_prometheus.urls'))
]

0 comments on commit cdf84d1

Please sign in to comment.