summary refs log tree commit diff
path: root/synapse/metrics
diff options
context:
space:
mode:
authorPaul "LeoNerd" Evans <paul@matrix.org>2015-03-04 19:43:46 +0000
committerPaul "LeoNerd" Evans <paul@matrix.org>2015-03-12 16:24:50 +0000
commitf52acf3b129864f400876f9316e1324e62e75eb0 (patch)
tree877abd09fe08c3dae46f66bce2af9192472e28f7 /synapse/metrics
parentNeater implementation of metric render methods by pulling out 'render' as a b... (diff)
downloadsynapse-f52acf3b129864f400876f9316e1324e62e75eb0.tar.xz
Neater register_* methods on overall Metrics container
Diffstat (limited to 'synapse/metrics')
-rw-r--r--synapse/metrics/__init__.py34
1 files changed, 12 insertions, 22 deletions
diff --git a/synapse/metrics/__init__.py b/synapse/metrics/__init__.py
index 442fd70cdf..e1818ce395 100644
--- a/synapse/metrics/__init__.py
+++ b/synapse/metrics/__init__.py
@@ -15,7 +15,7 @@
 
 import logging
 
-from .metric import CounterMetric, CallbackMetric, CacheMetric
+from .metric import CounterMetric, CallbackMetric, TimerMetric, CacheMetric
 
 
 logger = logging.getLogger(__name__)
@@ -36,35 +36,25 @@ class Metrics(object):
     def __init__(self, name):
         self.name_prefix = name
 
-    def _register(self, metric):
-        all_metrics[metric.name] = metric
-
-    def register_counter(self, name, *args, **kwargs):
-        full_name = "%s.%s" % (self.name_prefix, name)
-
-        metric = CounterMetric(full_name, *args, **kwargs)
-
-        self._register(metric)
-
-        return metric
-
-    def register_callback(self, name, callback, *args, **kwargs):
+    def _register(self, metric_class, name, *args, **kwargs):
         full_name = "%s.%s" % (self.name_prefix, name)
 
-        metric = CallbackMetric(full_name, *args, callback=callback, **kwargs)
-
-        self._register(metric)
+        metric = metric_class(full_name, *args, **kwargs)
 
+        all_metrics[full_name] = metric
         return metric
 
-    def register_cache(self, name, *args, **kwargs):
-        full_name = "%s.%s" % (self.name_prefix, name)
+    def register_counter(self, *args, **kwargs):
+        return self._register(CounterMetric, *args, **kwargs)
 
-        metric = CacheMetric(full_name, *args, **kwargs)
+    def register_callback(self, *args, **kwargs):
+        return self._register(CallbackMetric, *args, **kwargs)
 
-        self._register(metric)
+    def register_timer(self, *args, **kwargs):
+        return self._register(TimerMetric, *args, **kwargs)
 
-        return metric
+    def register_cache(self, *args, **kwargs):
+        return self._register(CacheMetric, *args, **kwargs)
 
     def counted(self, func):
         """ A method decorator that registers a counter, to count invocations