summary refs log tree commit diff
path: root/synapse/metrics
diff options
context:
space:
mode:
authorPaul "LeoNerd" Evans <paul@matrix.org>2015-03-04 17:34:23 +0000
committerPaul "LeoNerd" Evans <paul@matrix.org>2015-03-12 16:24:50 +0000
commit8664599af77ba0ed6268b3112174dc8e0c91101b (patch)
tree204e482555e1dbb4a0cf3731442a65d9aad91ed2 /synapse/metrics
parentEnsure that exceptions while rendering individual metrics don't stop others f... (diff)
downloadsynapse-8664599af77ba0ed6268b3112174dc8e0c91101b.tar.xz
Rename CacheCounterMetric to just CacheMetric; add a CallbackMetric component to give the size of the cache
Diffstat (limited to 'synapse/metrics')
-rw-r--r--synapse/metrics/__init__.py6
-rw-r--r--synapse/metrics/metric.py13
2 files changed, 12 insertions, 7 deletions
diff --git a/synapse/metrics/__init__.py b/synapse/metrics/__init__.py
index d967b04eee..442fd70cdf 100644
--- a/synapse/metrics/__init__.py
+++ b/synapse/metrics/__init__.py
@@ -15,7 +15,7 @@
 
 import logging
 
-from .metric import CounterMetric, CallbackMetric, CacheCounterMetric
+from .metric import CounterMetric, CallbackMetric, CacheMetric
 
 
 logger = logging.getLogger(__name__)
@@ -57,10 +57,10 @@ class Metrics(object):
 
         return metric
 
-    def register_cachecounter(self, name, *args, **kwargs):
+    def register_cache(self, name, *args, **kwargs):
         full_name = "%s.%s" % (self.name_prefix, name)
 
-        metric = CacheCounterMetric(full_name, *args, **kwargs)
+        metric = CacheMetric(full_name, *args, **kwargs)
 
         self._register(metric)
 
diff --git a/synapse/metrics/metric.py b/synapse/metrics/metric.py
index 8a497fc154..7e47f86155 100644
--- a/synapse/metrics/metric.py
+++ b/synapse/metrics/metric.py
@@ -76,19 +76,24 @@ class CallbackMetric(BaseMetric):
         # TODO(paul): work out something we can do with keys and vectors
         return ["%s %d" % (self.name, self.callback())]
 
-class CacheCounterMetric(object):
+class CacheMetric(object):
     """A combination of two CounterMetrics, one to count cache hits and one to
-    count misses.
+    count misses, and a callback metric to yield the current size.
 
     This metric generates standard metric name pairs, so that monitoring rules
     can easily be applied to measure hit ratio."""
 
-    def __init__(self, name, keys=[]):
+    def __init__(self, name, size_callback, keys=[]):
         self.name = name
 
         self.hits   = CounterMetric(name + ":hits",   keys=keys)
         self.misses = CounterMetric(name + ":misses", keys=keys)
 
+        self.size = CallbackMetric(name + ":size",
+            callback=size_callback,
+            keys=keys,
+        )
+
     def inc_hits(self, *values):
         self.hits.inc(*values)
 
@@ -96,4 +101,4 @@ class CacheCounterMetric(object):
         self.misses.inc(*values)
 
     def render(self):
-        return self.hits.render() + self.misses.render()
+        return self.hits.render() + self.misses.render() + self.size.render()