2
0
Fork 0

Implement basic metrics

This commit is contained in:
Luca 2022-05-18 14:36:13 +02:00
parent df9493f6cd
commit f5d2b7ee7c
10 changed files with 36 additions and 0 deletions

View File

View File

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

View File

@ -0,0 +1,6 @@
from django.apps import AppConfig
class MetricsConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "shiftregister.metrics"

View File

@ -0,0 +1,3 @@
from django.db import models
# Create your models here.

View File

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

View File

@ -0,0 +1,7 @@
from django.urls import path
from . import views
urlpatterns = [
path("", views.metrics, name="metrics"),
]

View File

@ -0,0 +1,12 @@
from django.http import HttpResponse
from shiftregister.app.models import Helper
def metrics(request):
response = HttpResponse("\n".join((f"shiftregister_{name} {value}" for name, value in (
("helpers_total", Helper.objects.count()),
("helpers_confirmed_total", Helper.objects.filter(number_validated=True).count()),
))))
response.headers["Content-Type"] = "text/plain"
return response

View File

@ -43,6 +43,7 @@ INSTALLED_APPS = [
"shiftregister.importer.apps.ImporterConfig",
"shiftregister.team.apps.TeamConfig",
"shiftregister.pages.apps.PagesConfig",
"shiftregister.metrics.apps.MetricsConfig",
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",

View File

@ -21,4 +21,5 @@ urlpatterns = [
path("team/", include("shiftregister.team.urls")),
path("admin/", admin.site.urls),
path("p/", include("shiftregister.pages.urls")),
path("metrics/", include("shiftregister.metrics.urls")),
]