Add basic metrics export

This commit is contained in:
Daan Sprenkels
2018-04-09 14:58:37 +02:00
parent 684710ebae
commit 17858c4aae
10 changed files with 42 additions and 0 deletions

View File

View File

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

5
marietje/metrics/apps.py Normal file
View File

@ -0,0 +1,5 @@
from django.apps import AppConfig
class MetricsConfig(AppConfig):
name = 'metrics'

View File

View File

@ -0,0 +1,3 @@
from django.db import models
# Create your models here.

View File

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

18
marietje/metrics/views.py Normal file
View 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")