Compare commits

...
Sign in to create a new pull request.

7 commits

Author SHA1 Message Date
4338d6b03a add container to testdata.py
Some checks failed
/ deploy (push) Failing after 3m12s
/ test (push) Successful in 2m48s
2024-12-27 21:37:59 +01:00
f6455638d7 add container to testdata.py
All checks were successful
/ test (push) Successful in 2m53s
/ deploy (push) Successful in 4m31s
2024-12-27 20:31:04 +01:00
3068597f3d metrics: also export ticket state
All checks were successful
/ test (push) Successful in 2m47s
/ deploy (push) Successful in 4m27s
2024-12-27 15:08:45 +01:00
7208aede8d Merge pull request 'metrics: Add ticket counters' (#110) from lagertonne/add-ticket-metrics into testing
All checks were successful
/ test (push) Successful in 2m39s
/ deploy (push) Successful in 4m32s
2024-12-27 08:41:55 +00:00
c569d29d8a metrics: Add ticket counters
All checks were successful
/ test (push) Successful in 2m41s
/ test (pull_request) Successful in 2m34s
2024-12-27 09:34:54 +01:00
a2f7682c6f Merge pull request 'metrics: Fix bug when running migrate on empty db' (#109) from lagertonne/fix-db-creation-with-metrics into testing
All checks were successful
/ test (push) Successful in 2m52s
/ deploy (push) Successful in 4m37s
2024-12-26 19:52:28 +00:00
e234385802 metrics: Fix bug when running migrate on empty db
All checks were successful
/ test (push) Successful in 2m49s
/ test (pull_request) Successful in 2m47s
2024-12-26 19:49:12 +00:00
4 changed files with 46 additions and 10 deletions

View file

@ -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):
@ -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())

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

@ -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")

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