From 6ce0934ed51a0e1e06e639cb30b885b326d0e5da Mon Sep 17 00:00:00 2001 From: Jonathan Slenders Date: Wed, 3 Sep 2014 15:19:07 +0200 Subject: [PATCH] Showing sum/lower/mean/upper values in debugbar panel. --- django_statsd/panel.py | 34 ++++++++++- .../templates/toolbar_statsd/statsd.html | 58 +++++++++++++++---- 2 files changed, 80 insertions(+), 12 deletions(-) diff --git a/django_statsd/panel.py b/django_statsd/panel.py index c13a7b3..fd4de88 100644 --- a/django_statsd/panel.py +++ b/django_statsd/panel.py @@ -1,3 +1,5 @@ +from collections import defaultdict + from django.conf import settings from django.utils.translation import ugettext_lazy as _, ungettext @@ -43,6 +45,35 @@ def times(stats): duration_ratio_relative * 100.0, duration, ]) + results.sort(key=lambda r: r[1]) + return results + + +def times_summary(stats): + results = [] + if not stats: + return results + + timings = defaultdict(list) + for stat in stats: + timings[stat[0].split('|')[0]].append(stat[2]) + + for stat, v in timings.iteritems(): + if not v: + continue + v.sort() + count = len(v) + vmin, vmax = v[0], v[-1] + vsum = sum(v) + mean = vsum / float(count) + results.append({ + 'stat': stat, + 'count': count, + 'sum': vsum, + 'lower': vmin, + 'upper': vmax, + 'mean': mean, + }) return results @@ -76,5 +107,6 @@ class StatsdPanel(Panel): self.record_stats({ 'graphite': config.get('graphite'), 'statsd': munge(self.statsd.cache), - 'timings': times(self.statsd.timings) + 'timings': times(self.statsd.timings), + 'timings_summary': times_summary(self.statsd.timings), }) diff --git a/django_statsd/templates/toolbar_statsd/statsd.html b/django_statsd/templates/toolbar_statsd/statsd.html index fce887e..d25d221 100644 --- a/django_statsd/templates/toolbar_statsd/statsd.html +++ b/django_statsd/templates/toolbar_statsd/statsd.html @@ -2,31 +2,57 @@ data-graphite="{{ graphite }}" data-roots-timers="{% for root in timers %}{{ root }}{% if not forloop.last %}|{% endif %}{% endfor %}" data-roots-counts="{% for root in counts %}{{ root }}{% if not forloop.last %}|{% endif %}{% endfor %}"> - +
- - + + + + + + + + + {% for value in timings_summary %} + + + + + + + + + {% endfor %} + +
StatTimingTimeCountSumLowerMeanUpper
{{ value.stat }}{{ value.count }}{{ value.sum }}{{ value.lower }}{{ value.mean|floatformat:"2" }}{{ value.upper }}
+ + + + + + {% for value in timings %} + - {% endfor %}
StatTime (ms)Timing
{{ value.0 }}{{ value.3 }}
-
-   +
+   +
+
+  
{{ value.3 }}ms
- @@ -57,7 +83,7 @@
-
+