Metrics: Count model instances in database

This commit is contained in:
Raphael Michel
2017-03-27 21:58:38 +02:00
parent 99395c722d
commit bcdb4fd000
+11 -7
View File
@@ -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