metrics: also export ticket state
All checks were successful
/ test (push) Successful in 2m47s
/ deploy (push) Successful in 4m27s

This commit is contained in:
j3d1 2024-12-27 15:08:45 +01:00
parent 7208aede8d
commit 3068597f3d
3 changed files with 19 additions and 19 deletions

View file

@ -4,6 +4,8 @@ from django.db.models import Case, Value, When, BooleanField, Count
from inventory.models import Item from inventory.models import Item
from tickets.models import IssueThread from tickets.models import IssueThread
from itertools import groupby
class ItemCountCollector(object): class ItemCountCollector(object):
@ -34,27 +36,23 @@ class ItemCountCollector(object):
yield counter yield counter
class TicketCountCollector(object): class TicketCountCollector(object):
def collect(self): def collect(self):
counter = CounterMetricFamily("c3lf_ticket_count", "Current number of tickets", labels=['event', 'event_id']) counter = CounterMetricFamily("c3lf_ticket_count", "Current number of tickets", labels=['event', 'event_id'])
yield counter
if not apps.models_ready or not apps.apps_ready: if not apps.models_ready or not apps.apps_ready:
return return
queryset = ( g = groupby(IssueThread.objects.all().prefetch_related('event', 'state_changes'),
IssueThread.objects lambda x: (x.event.slug, x.state))
.values('event__slug', 'event_id') for (event, state), v in g:
.annotate(amount=Count('id')) counter.add_metric([event.lower(), state.lower()], len(list(v)))
)
for e in queryset:
counter.add_metric([e["event__slug"].lower()], e["amount"])
yield counter yield counter
try: try:
REGISTRY.register(ItemCountCollector()) REGISTRY.register(ItemCountCollector())
REGISTRY.register(TicketCountCollector()) REGISTRY.register(TicketCountCollector())

View file

@ -7,6 +7,7 @@ services:
environment: environment:
- HTTP_HOST=core - HTTP_HOST=core
- DB_FILE=dev.db - DB_FILE=dev.db
- DEBUG_MODE_ACTIVE=yup
volumes: volumes:
- ../../core:/code - ../../core:/code
- ../testdata.py:/code/testdata.py - ../testdata.py:/code/testdata.py

View file

@ -30,6 +30,7 @@ services:
- DB_USER=system3 - DB_USER=system3
- DB_PASSWORD=system3 - DB_PASSWORD=system3
- MAIL_DOMAIN=mail:1025 - MAIL_DOMAIN=mail:1025
- DEBUG_MODE_ACTIVE=certainly
volumes: volumes:
- ../../core:/code - ../../core:/code
- ../testdata.py:/code/testdata.py - ../testdata.py:/code/testdata.py