WIP: Add the django standard metrics

This commit is contained in:
lagertonne 2024-11-06 22:21:32 +01:00
parent d2a38b8327
commit e156df726a
4 changed files with 17 additions and 0 deletions

8
core/core/metrics.py Normal file
View file

@ -0,0 +1,8 @@
from prometheus_client import Counter, Gauge
from django_prometheus.middleware import (
PrometheusAfterMiddleware,
)
class AppMetricsAfterMiddleware(PrometheusAfterMiddleware):
def register_metric(self, metric_cls, name, documentation, labelnames=(), **kwargs):
return super().register_metric(metric_cls, name, documentation, labelnames=labelnames, **kwargs)

View file

@ -50,6 +50,7 @@ INSTALLED_APPS = [
'django.contrib.messages',
'django.contrib.staticfiles',
'django_extensions',
'django_prometheus',
'rest_framework',
'knox',
'drf_yasg',
@ -85,6 +86,7 @@ SWAGGER_SETTINGS = {
}
MIDDLEWARE = [
'django_prometheus.middleware.PrometheusBeforeMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
@ -92,6 +94,7 @@ MIDDLEWARE = [
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django_prometheus.middleware.PrometheusAfterMiddleware',
]
ROOT_URLCONF = 'core.urls'
@ -210,4 +213,6 @@ CHANNEL_LAYERS = {
}
PROMETHEUS_METRIC_NAMESPACE = 'c3lf'
TEST_RUNNER = 'core.test_runner.FastTestRunner'

View file

@ -18,6 +18,7 @@ from django.contrib import admin
from django.urls import path, include
from .version import get_info
from .metrics import CustomMetrics
urlpatterns = [
path('djangoadmin/', admin.site.urls),
@ -32,4 +33,5 @@ urlpatterns = [
path('api/2/', include('notify_sessions.api_v2')),
path('api/2/', include('authentication.api_v2')),
path('api/', get_info),
path('', include('django_prometheus.urls')),
]

View file

@ -38,3 +38,5 @@ urllib3==2.1.0
uvicorn==0.24.0.post1
watchfiles==0.21.0
websockets==12.0
django-prometheus==2.3.1
prometheus_client==0.21.0