From f5d2b7ee7c453687135828584a3e16bb1261adda Mon Sep 17 00:00:00 2001 From: Luca Date: Wed, 18 May 2022 14:36:13 +0200 Subject: [PATCH] Implement basic metrics --- shiftregister/metrics/__init__.py | 0 shiftregister/metrics/admin.py | 3 +++ shiftregister/metrics/apps.py | 6 ++++++ shiftregister/metrics/migrations/__init__.py | 0 shiftregister/metrics/models.py | 3 +++ shiftregister/metrics/tests.py | 3 +++ shiftregister/metrics/urls.py | 7 +++++++ shiftregister/metrics/views.py | 12 ++++++++++++ shiftregister/settings.py | 1 + shiftregister/urls.py | 1 + 10 files changed, 36 insertions(+) create mode 100644 shiftregister/metrics/__init__.py create mode 100644 shiftregister/metrics/admin.py create mode 100644 shiftregister/metrics/apps.py create mode 100644 shiftregister/metrics/migrations/__init__.py create mode 100644 shiftregister/metrics/models.py create mode 100644 shiftregister/metrics/tests.py create mode 100644 shiftregister/metrics/urls.py create mode 100644 shiftregister/metrics/views.py diff --git a/shiftregister/metrics/__init__.py b/shiftregister/metrics/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/shiftregister/metrics/admin.py b/shiftregister/metrics/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/shiftregister/metrics/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/shiftregister/metrics/apps.py b/shiftregister/metrics/apps.py new file mode 100644 index 0000000..56329f6 --- /dev/null +++ b/shiftregister/metrics/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class MetricsConfig(AppConfig): + default_auto_field = "django.db.models.BigAutoField" + name = "shiftregister.metrics" diff --git a/shiftregister/metrics/migrations/__init__.py b/shiftregister/metrics/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/shiftregister/metrics/models.py b/shiftregister/metrics/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/shiftregister/metrics/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/shiftregister/metrics/tests.py b/shiftregister/metrics/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/shiftregister/metrics/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/shiftregister/metrics/urls.py b/shiftregister/metrics/urls.py new file mode 100644 index 0000000..30dff2f --- /dev/null +++ b/shiftregister/metrics/urls.py @@ -0,0 +1,7 @@ +from django.urls import path + +from . import views + +urlpatterns = [ + path("", views.metrics, name="metrics"), +] diff --git a/shiftregister/metrics/views.py b/shiftregister/metrics/views.py new file mode 100644 index 0000000..f316446 --- /dev/null +++ b/shiftregister/metrics/views.py @@ -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 diff --git a/shiftregister/settings.py b/shiftregister/settings.py index 6de9f54..c3c0f20 100644 --- a/shiftregister/settings.py +++ b/shiftregister/settings.py @@ -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", diff --git a/shiftregister/urls.py b/shiftregister/urls.py index d123eba..bfc9a6b 100644 --- a/shiftregister/urls.py +++ b/shiftregister/urls.py @@ -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")), ]