summary refs log tree commit diff
path: root/synapse/metrics
diff options
context:
space:
mode:
authorPaul "LeoNerd" Evans <paul@matrix.org>2016-10-19 17:54:09 +0100
committerPaul "LeoNerd" Evans <paul@matrix.org>2016-10-19 17:54:09 +0100
commit4cedd532246278361f31f93216103d769b40650c (patch)
treef0af38a4793cd330fbff8cf25ec037f26f81af8e /synapse/metrics
parentappease pep8 (diff)
downloadsynapse-4cedd532246278361f31f93216103d769b40650c.tar.xz
A slightly neater way to manage metric collector functions
Diffstat (limited to 'synapse/metrics')
-rw-r--r--synapse/metrics/__init__.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/synapse/metrics/__init__.py b/synapse/metrics/__init__.py
index ea8219a77c..9d18b0fbfe 100644
--- a/synapse/metrics/__init__.py
+++ b/synapse/metrics/__init__.py
@@ -36,6 +36,7 @@ logger = logging.getLogger(__name__)
 
 
 all_metrics = []
+all_collectors = []
 
 
 class Metrics(object):
@@ -46,6 +47,9 @@ class Metrics(object):
     def __init__(self, name):
         self.name_prefix = name
 
+    def register_collector(self, func):
+        all_collectors.append(func)
+
     def _register(self, metric_class, name, *args, **kwargs):
         full_name = "%s_%s" % (self.name_prefix, name)
 
@@ -94,8 +98,8 @@ def get_metrics_for(pkg_name):
 def render_all():
     strs = []
 
-    # TODO(paul): Internal hack
-    update_resource_metrics()
+    for collector in all_collectors:
+        collector()
 
     for metric in all_metrics:
         try:
@@ -188,6 +192,8 @@ def _process_fds():
 
 resource_metrics = get_metrics_for("process.resource")
 
+resource_metrics.register_collector(update_resource_metrics)
+
 # msecs
 resource_metrics.register_callback("utime", lambda: rusage.ru_utime * 1000)
 resource_metrics.register_callback("stime", lambda: rusage.ru_stime * 1000)