summary refs log tree commit diff
path: root/synapse/metrics/metric.py
diff options
context:
space:
mode:
authorPaul "LeoNerd" Evans <paul@matrix.org>2015-03-04 16:46:44 +0000
committerPaul "LeoNerd" Evans <paul@matrix.org>2015-03-12 16:24:50 +0000
commitd8caa5454d781a76a65fa4ce75336541b973f624 (patch)
tree949ce9f638861c360722fbbb3161193c4dabec7c /synapse/metrics/metric.py
parentSprinkle some CacheCounterMetrics around the synapse.storage layer (diff)
downloadsynapse-d8caa5454d781a76a65fa4ce75336541b973f624.tar.xz
Initial attempt at a scalar callback-based metric to give instantaneous snapshot gauges
Diffstat (limited to 'synapse/metrics/metric.py')
-rw-r--r--synapse/metrics/metric.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/synapse/metrics/metric.py b/synapse/metrics/metric.py
index 00b149f6f6..8a497fc154 100644
--- a/synapse/metrics/metric.py
+++ b/synapse/metrics/metric.py
@@ -62,6 +62,20 @@ class CounterMetric(BaseMetric):
                 for k in sorted(self.counts.keys())]
 
 
+class CallbackMetric(BaseMetric):
+    """A metric that returns the numeric value returned by a callback whenever
+    it is rendered. Typically this is used to implement gauges that yield the
+    size or other state of some in-memory object by actively querying it."""
+
+    def __init__(self, name, callback, keys=[]):
+        super(CallbackMetric, self).__init__(name, keys=keys)
+
+        self.callback = callback
+
+    def render(self):
+        # TODO(paul): work out something we can do with keys and vectors
+        return ["%s %d" % (self.name, self.callback())]
+
 class CacheCounterMetric(object):
     """A combination of two CounterMetrics, one to count cache hits and one to
     count misses.