mirror of
https://github.com/pretix/pretix.git
synced 2026-05-05 15:14:04 +00:00
Metrics: Replace redundant metrics by aliases
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import math
|
||||
from collections import defaultdict
|
||||
|
||||
from django.apps import apps
|
||||
from django.conf import settings
|
||||
@@ -186,20 +187,28 @@ class Histogram(Metric):
|
||||
|
||||
def metric_values():
|
||||
"""
|
||||
Produces the scrapable textformat to be presented to the monitoring system
|
||||
Produces the the values to be presented to the monitoring system
|
||||
"""
|
||||
metrics = {}
|
||||
metrics = defaultdict(dict)
|
||||
|
||||
# Metrics from redis
|
||||
if settings.HAS_REDIS:
|
||||
for key, value in redis.hscan_iter(REDIS_KEY):
|
||||
dkey = key.decode("utf-8")
|
||||
splitted = dkey.split("{", 2)
|
||||
value = float(value.decode("utf-8"))
|
||||
metrics[dkey] = value
|
||||
metrics[splitted[0]]["{" + splitted[1]] = value
|
||||
|
||||
# Aliases
|
||||
aliases = {
|
||||
'pretix_view_requests_total': 'pretix_view_duration_seconds_count'
|
||||
}
|
||||
for a, atarget in aliases.items():
|
||||
metrics[a] = metrics[atarget]
|
||||
|
||||
# Throwaway metrics
|
||||
for m in apps.get_models(): # Count all models
|
||||
metrics['pretix_model_instances{model="%s"}' % m._meta] = m.objects.count()
|
||||
metrics['pretix_model_instances']['{model="%s"}' % m._meta] = m.objects.count()
|
||||
|
||||
return metrics
|
||||
|
||||
@@ -207,8 +216,6 @@ def metric_values():
|
||||
"""
|
||||
Provided metrics
|
||||
"""
|
||||
pretix_view_requests_total = Counter("pretix_view_requests_total", "Total number of HTTP requests made.",
|
||||
["status_code", "method", "url_name"])
|
||||
pretix_view_duration_seconds = Histogram("pretix_view_duration_seconds", "Return time of views.",
|
||||
["status_code", "method", "url_name"])
|
||||
pretix_task_runs_total = Counter("pretix_task_runs_total", "Total calls to a celery task",
|
||||
|
||||
@@ -38,8 +38,9 @@ def serve_metrics(request):
|
||||
m = metrics.metric_values()
|
||||
|
||||
output = []
|
||||
for metric, value in m.items():
|
||||
output.append("{} {}".format(metric, str(value)))
|
||||
for metric, sub in m.items():
|
||||
for label, value in sub.items():
|
||||
output.append("{}{} {}".format(metric, label, str(value)))
|
||||
|
||||
content = "\n".join(output) + "\n"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user