mirror of
https://gitlab.science.ru.nl/technicie/MarietjeDjango.git
synced 2025-12-10 08:02:26 +01:00
Add basic metrics export
This commit is contained in:
0
marietje/metrics/__init__.py
Normal file
0
marietje/metrics/__init__.py
Normal file
3
marietje/metrics/admin.py
Normal file
3
marietje/metrics/admin.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
5
marietje/metrics/apps.py
Normal file
5
marietje/metrics/apps.py
Normal file
@ -0,0 +1,5 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class MetricsConfig(AppConfig):
|
||||
name = 'metrics'
|
||||
0
marietje/metrics/migrations/__init__.py
Normal file
0
marietje/metrics/migrations/__init__.py
Normal file
3
marietje/metrics/models.py
Normal file
3
marietje/metrics/models.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
3
marietje/metrics/tests.py
Normal file
3
marietje/metrics/tests.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
18
marietje/metrics/views.py
Normal file
18
marietje/metrics/views.py
Normal file
@ -0,0 +1,18 @@
|
||||
from prometheus_client import generate_latest, Gauge
|
||||
|
||||
from django.db.models import Q
|
||||
from django.http import HttpResponse
|
||||
|
||||
from queues.models import Queue, PlaylistSong
|
||||
|
||||
# Export queue length
|
||||
g = Gauge('marietje_queue_length', 'Marietje queue length', ['name'])
|
||||
for queue in Queue.objects.all():
|
||||
def _get_queue_length():
|
||||
return PlaylistSong.objects.filter(Q(playlist=queue.playlist_id),
|
||||
Q(state=0) | Q(state=1)).count()
|
||||
g.labels(name=queue).set_function(_get_queue_length)
|
||||
|
||||
|
||||
def metrics(request):
|
||||
return HttpResponse(generate_latest(), content_type="text/plain")
|
||||
Reference in New Issue
Block a user