combine all prometheus metrics in one view

This commit is contained in:
Jenny Danzmayr 2024-09-20 01:09:45 +02:00
parent 75ff32fc60
commit 60de7857d6
2 changed files with 8 additions and 6 deletions

View file

@ -484,10 +484,13 @@ def get_cache_package(request, filetype):
return response
def api_stats_exporter(request):
def prometheus_exporter(request):
"""Exports the API metrics for Prometheus"""
import prometheus_client
from django_prometheus.exports import ExportToDjangoView
from c3nav.mapdata.metrics import REGISTRY
metrics_page = prometheus_client.generate_latest(REGISTRY)
return HttpResponse(metrics_page, content_type=prometheus_client.CONTENT_TYPE_LATEST)
response = ExportToDjangoView(request)
response.content += metrics_page
return response

View file

@ -50,11 +50,10 @@ if settings.SERVE_ANYTHING:
if settings.METRICS:
with suppress(ImportError):
import django_prometheus.urls # noqu
from c3nav.mapdata.views import api_stats_exporter
import django_prometheus # noqu
from c3nav.mapdata.views import prometheus_exporter
urlpatterns += [
path('prometheus/api_metrics', api_stats_exporter),
path('prometheus/', include(django_prometheus.urls)),
path('prometheus/metrics', prometheus_exporter, name='prometheus-exporter'),
]
if settings.SSO_ENABLED: