mirror of
https://github.com/pretix/pretix.git
synced 2026-08-29 13:44:40 +00:00
Metrics: Count model instances in database
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import math
|
import math
|
||||||
|
|
||||||
|
from django.apps import apps
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
if settings.HAS_REDIS:
|
if settings.HAS_REDIS:
|
||||||
@@ -187,15 +188,18 @@ def metric_values():
|
|||||||
"""
|
"""
|
||||||
Produces the scrapable textformat to be presented to the monitoring system
|
Produces the scrapable textformat to be presented to the monitoring system
|
||||||
"""
|
"""
|
||||||
if not settings.HAS_REDIS:
|
|
||||||
return ""
|
|
||||||
|
|
||||||
metrics = {}
|
metrics = {}
|
||||||
|
|
||||||
for key, value in redis.hscan_iter(REDIS_KEY):
|
# Metrics from redis
|
||||||
dkey = key.decode("utf-8")
|
if settings.HAS_REDIS:
|
||||||
value = float(value.decode("utf-8"))
|
for key, value in redis.hscan_iter(REDIS_KEY):
|
||||||
metrics[dkey] = value
|
dkey = key.decode("utf-8")
|
||||||
|
value = float(value.decode("utf-8"))
|
||||||
|
metrics[dkey] = value
|
||||||
|
|
||||||
|
# Throwaway metrics
|
||||||
|
for m in apps.get_models(): # Count all models
|
||||||
|
metrics['pretix_model_instances{model="%s"}' % m._meta] = m.objects.count()
|
||||||
|
|
||||||
return metrics
|
return metrics
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user