2024-01-17 18:03:10 +00:00
|
|
|
from django.shortcuts import render
|
|
|
|
from django.http import HttpResponse
|
|
|
|
from django.views.decorators.http import require_GET
|
|
|
|
from prometheus_client.exposition import generate_latest
|
|
|
|
from prometheus_client import REGISTRY, CONTENT_TYPE_LATEST
|
2024-01-24 19:28:12 +00:00
|
|
|
from .custom_metrics import (
|
|
|
|
actualizar_metrica_usuarios,
|
|
|
|
actualizar_metrica_websites,
|
|
|
|
actualizar_metrica_databases,
|
|
|
|
actualizar_metrica_mailboxes,
|
|
|
|
actualizar_metrica_lists,
|
|
|
|
actualizar_metrica_saas,
|
|
|
|
)
|
2024-01-17 18:03:10 +00:00
|
|
|
|
|
|
|
@require_GET
|
|
|
|
def metrics_view(request):
|
|
|
|
# Actualizar métricas antes de generar el contenido
|
|
|
|
actualizar_metrica_usuarios()
|
|
|
|
actualizar_metrica_websites()
|
2024-01-24 17:58:54 +00:00
|
|
|
actualizar_metrica_databases()
|
2024-01-24 19:28:12 +00:00
|
|
|
actualizar_metrica_mailboxes()
|
|
|
|
actualizar_metrica_lists()
|
|
|
|
actualizar_metrica_saas()
|
2024-01-17 18:03:10 +00:00
|
|
|
|
|
|
|
# Devolver las métricas exportadas como respuesta HTTP
|
|
|
|
output = generate_latest(REGISTRY)
|
|
|
|
return HttpResponse(output, content_type=CONTENT_TYPE_LATEST)
|