diff --git a/core/core/metrics.py b/core/core/metrics.py deleted file mode 100644 index 16a826d..0000000 --- a/core/core/metrics.py +++ /dev/null @@ -1,35 +0,0 @@ -from django.apps import apps -from prometheus_client.core import CounterMetricFamily, REGISTRY -from django.db.models import Case, Value, When, BooleanField, Count -from inventory.models import Item - -class ItemCountCollector(object): - - def collect(self): - counter = CounterMetricFamily("item_count", "Current number of items", labels=['event', 'state']) - - yield counter - - if not apps.models_ready or not apps.apps_ready: - return - - queryset = ( - Item.all_objects - .annotate( - returned=Case( - When(returned_at__isnull=False, then=Value(False)), - default=Value(True), - output_field=BooleanField() - ) - ) - .values('event__slug', 'returned', 'event_id') - .annotate(amount=Count('id')) - .order_by('event__slug', 'returned') # Optional: order by slug and returned - ) - - for e in queryset: - counter.add_metric([e["event__slug"].lower(), str(e["returned"])], e["amount"]) - - yield counter - -REGISTRY.register(ItemCountCollector()) \ No newline at end of file diff --git a/core/core/urls.py b/core/core/urls.py index 2386891..1c5f158 100644 --- a/core/core/urls.py +++ b/core/core/urls.py @@ -19,8 +19,6 @@ from django.urls import path, include from .version import get_info -from .metrics import * - urlpatterns = [ path('djangoadmin/', admin.site.urls), path('api/2/', include('inventory.api_v2')),