Compare commits
7 commits
testing
...
testing_st
Author | SHA1 | Date | |
---|---|---|---|
4338d6b03a | |||
f6455638d7 | |||
3068597f3d | |||
7208aede8d | |||
c569d29d8a | |||
a2f7682c6f | |||
e234385802 |
4 changed files with 46 additions and 10 deletions
|
@ -2,6 +2,10 @@ 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
|
||||||
|
|
||||||
|
from itertools import groupby
|
||||||
|
|
||||||
|
|
||||||
class ItemCountCollector(object):
|
class ItemCountCollector(object):
|
||||||
|
|
||||||
|
@ -15,16 +19,16 @@ class ItemCountCollector(object):
|
||||||
|
|
||||||
queryset = (
|
queryset = (
|
||||||
Item.all_objects
|
Item.all_objects
|
||||||
.annotate(
|
.annotate(
|
||||||
returned=Case(
|
returned=Case(
|
||||||
When(returned_at__isnull=True, then=Value(False)),
|
When(returned_at__isnull=True, then=Value(False)),
|
||||||
default=Value(True),
|
default=Value(True),
|
||||||
output_field=BooleanField()
|
output_field=BooleanField()
|
||||||
)
|
|
||||||
)
|
)
|
||||||
.values('event__slug', 'returned', 'event_id')
|
)
|
||||||
.annotate(amount=Count('id'))
|
.values('event__slug', 'returned', 'event_id')
|
||||||
.order_by('event__slug', 'returned') # Optional: order by slug and returned
|
.annotate(amount=Count('id'))
|
||||||
|
.order_by('event__slug', 'returned') # Optional: order by slug and returned
|
||||||
)
|
)
|
||||||
|
|
||||||
for e in queryset:
|
for e in queryset:
|
||||||
|
@ -32,4 +36,25 @@ 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
|
||||||
|
|
||||||
|
g = groupby(IssueThread.objects.all().prefetch_related('event', 'state_changes'),
|
||||||
|
lambda x: (x.event.slug, x.state))
|
||||||
|
for (event, state), v in g:
|
||||||
|
counter.add_metric([event.lower(), state.lower()], len(list(v)))
|
||||||
|
|
||||||
|
yield counter
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
REGISTRY.register(ItemCountCollector())
|
REGISTRY.register(ItemCountCollector())
|
||||||
|
REGISTRY.register(TicketCountCollector())
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -70,6 +70,15 @@ def setup():
|
||||||
issue_thread=issue_thread,
|
issue_thread=issue_thread,
|
||||||
)[0]
|
)[0]
|
||||||
|
|
||||||
|
from inventory.models import Container
|
||||||
|
|
||||||
|
Container.objects.get_or_create(
|
||||||
|
id=1,
|
||||||
|
name='testcontainer'
|
||||||
|
)[0]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "core.settings")
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "core.settings")
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Add table
Reference in a new issue