metrics: Add the first (simple) custom metrics
This commit is contained in:
parent
b31f3758e0
commit
933ee617ff
9 changed files with 60 additions and 0 deletions
0
core/core/management/__init__.py
Normal file
0
core/core/management/__init__.py
Normal file
0
core/core/management/commands/__init__.py
Normal file
0
core/core/management/commands/__init__.py
Normal file
8
core/core/management/commands/update_metrics.py
Normal file
8
core/core/management/commands/update_metrics.py
Normal 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
11
core/core/metrics.py
Normal 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)
|
|
@ -70,6 +70,7 @@ INSTALLED_APPS = [
|
|||
'inventory',
|
||||
'mail',
|
||||
'notify_sessions',
|
||||
'core'
|
||||
]
|
||||
|
||||
REST_FRAMEWORK = {
|
||||
|
|
|
@ -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')),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue