From 0b96bb793e7e5d3935804b8f0ccaf415006388a9 Mon Sep 17 00:00:00 2001 From: "Paul \"LeoNerd\" Evans" Date: Fri, 6 Mar 2015 15:39:14 +0000 Subject: [PATCH] Have all @metrics.counted use a single metric name vectored on the method name, rather than a brand new scalar counter per counted method --- synapse/metrics/__init__.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/synapse/metrics/__init__.py b/synapse/metrics/__init__.py index c00f088ff..443d67f41 100644 --- a/synapse/metrics/__init__.py +++ b/synapse/metrics/__init__.py @@ -63,10 +63,17 @@ class Metrics(object): def counted(self, func): """ A method decorator that registers a counter, to count invocations of this method. """ - counter = self.register_counter(func.__name__) + if not hasattr(self, "method_counter"): + self.method_counter = self.register_counter( + "calls", + labels=["method"] + ) + + counter = self.method_counter + name = func.__name__ def wrapped(*args, **kwargs): - counter.inc() + counter.inc(name) return func(*args, **kwargs) return wrapped