metrics: Add ticket counters #110
1 changed files with 24 additions and 0 deletions
|
@ -2,6 +2,8 @@ from django.apps import apps
|
||||||
from prometheus_client.core import CounterMetricFamily, REGISTRY
|
from prometheus_client.core import CounterMetricFamily, REGISTRY
|
||||||
from django.db.models import Case, Value, When, BooleanField, Count
|
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
|
||||||
|
|
||||||
|
|
||||||
class ItemCountCollector(object):
|
class ItemCountCollector(object):
|
||||||
|
|
||||||
|
@ -32,7 +34,29 @@ class ItemCountCollector(object):
|
||||||
|
|
||||||
yield counter
|
yield counter
|
||||||
|
|
||||||
|
class TicketCountCollector(object):
|
||||||
|
|
||||||
|
def collect(self):
|
||||||
|
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:
|
||||||
|
return
|
||||||
|
|
||||||
|
queryset = (
|
||||||
|
IssueThread.objects
|
||||||
|
.values('event__slug', 'event_id')
|
||||||
|
.annotate(amount=Count('id'))
|
||||||
|
)
|
||||||
|
|
||||||
|
for e in queryset:
|
||||||
|
counter.add_metric([e["event__slug"].lower()], e["amount"])
|
||||||
|
|
||||||
|
yield counter
|
||||||
|
|
||||||
try:
|
try:
|
||||||
REGISTRY.register(ItemCountCollector())
|
REGISTRY.register(ItemCountCollector())
|
||||||
|
REGISTRY.register(TicketCountCollector())
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
|
|
Loading…
Add table
Reference in a new issue