summary refs log tree commit diff
path: root/synapse/metrics
diff options
context:
space:
mode:
Diffstat (limited to 'synapse/metrics')
-rw-r--r--synapse/metrics/__init__.py6
-rw-r--r--synapse/metrics/process_collector.py10
2 files changed, 9 insertions, 7 deletions
diff --git a/synapse/metrics/__init__.py b/synapse/metrics/__init__.py
index a6b868775d..7041da25ce 100644
--- a/synapse/metrics/__init__.py
+++ b/synapse/metrics/__init__.py
@@ -24,6 +24,7 @@ from .metric import (
     CounterMetric, CallbackMetric, DistributionMetric, CacheMetric,
     MemoryUsageMetric,
 )
+from .process_collector import register_process_collector
 
 
 logger = logging.getLogger(__name__)
@@ -41,6 +42,9 @@ class Metrics(object):
     def __init__(self, name):
         self.name_prefix = name
 
+    def make_subspace(self, name):
+        return Metrics("%s_%s" % (self.name_prefix, name))
+
     def register_collector(self, func):
         all_collectors.append(func)
 
@@ -118,6 +122,8 @@ reactor_metrics.register_callback(
     "gc_counts", lambda: {(i,): v for i, v in enumerate(gc.get_count())}, labels=["gen"]
 )
 
+register_process_collector(get_metrics_for("process"))
+
 
 def runUntilCurrentTimer(func):
 
diff --git a/synapse/metrics/process_collector.py b/synapse/metrics/process_collector.py
index 1c851d9234..0e95582368 100644
--- a/synapse/metrics/process_collector.py
+++ b/synapse/metrics/process_collector.py
@@ -20,8 +20,6 @@ import os
 import stat
 from resource import getrusage, RUSAGE_SELF
 
-from synapse.metrics import get_metrics_for
-
 
 TICKS_PER_SEC = 100
 BYTES_PER_PAGE = 4096
@@ -111,10 +109,10 @@ def _process_fds():
     return counts
 
 
-def register_process_collector():
+def register_process_collector(process_metrics):
     # Legacy synapse-invented metric names
 
-    resource_metrics = get_metrics_for("process.resource")
+    resource_metrics = process_metrics.make_subspace("resource")
 
     resource_metrics.register_collector(update_resource_metrics)
 
@@ -125,12 +123,10 @@ def register_process_collector():
     # kilobytes
     resource_metrics.register_callback("maxrss", lambda: rusage.ru_maxrss * 1024)
 
-    get_metrics_for("process").register_callback("fds", _process_fds, labels=["type"])
+    process_metrics.register_callback("fds", _process_fds, labels=["type"])
 
     # New prometheus-standard metric names
 
-    process_metrics = get_metrics_for("process")
-
     if HAVE_PROC_SELF_STAT:
         process_metrics.register_callback(
             "cpu_user_seconds_total",