metrics: Add the first (simple) custom metrics
All checks were successful
/ test (pull_request) Successful in 2m36s
/ test (push) Successful in 2m41s
/ deploy (push) Successful in 4m33s

This commit is contained in:
lagertonne 2024-12-21 12:51:38 +01:00
parent b31f3758e0
commit 933ee617ff
9 changed files with 60 additions and 0 deletions

View file

View file

@ -0,0 +1,8 @@
from django.core.management.base import BaseCommand, CommandError
from core.metrics import update_item_count
class Command(BaseCommand):
help = "Refresh the metrics"
def handle(self, *args, **options):
update_item_count()

11
core/core/metrics.py Normal file
View file

@ -0,0 +1,11 @@
from prometheus_client import Gauge
from django_prometheus import exports
from inventory.models import *
g_items_total = Gauge('c3lf_items_total', 'Current Total items')
def update_item_count():
# Get the count of MyModel objects
count = Item.objects.count()
# Set the gauge to the current count
g_items_total.set(count)

View file

@ -70,6 +70,7 @@ INSTALLED_APPS = [
'inventory',
'mail',
'notify_sessions',
'core'
]
REST_FRAMEWORK = {

View file

@ -19,6 +19,8 @@ from django.urls import path, include
from .version import get_info
from .metrics import *
urlpatterns = [
path('djangoadmin/', admin.site.urls),
path('api/2/', include('inventory.api_v2')),