summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--synapse/metrics/__init__.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/synapse/metrics/__init__.py b/synapse/metrics/__init__.py
index e1818ce395..c00f088fff 100644
--- a/synapse/metrics/__init__.py
+++ b/synapse/metrics/__init__.py
@@ -13,7 +13,11 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+# Because otherwise 'resource' collides with synapse.metrics.resource
+from __future__ import absolute_import
+
 import logging
+from resource import getrusage, getpagesize, RUSAGE_SELF
 
 from .metric import CounterMetric, CallbackMetric, TimerMetric, CacheMetric
 
@@ -76,6 +80,9 @@ def get_metrics_for(name):
 def render_all():
     strs = []
 
+    # TODO(paul): Internal hack
+    update_resource_metrics()
+
     for name in sorted(all_metrics.keys()):
         try:
             strs += all_metrics[name].render()
@@ -84,3 +91,23 @@ def render_all():
             logger.exception("Failed to render %s metric", name)
 
     return "\n".join(strs)
+
+
+# Now register some standard process-wide state metrics, to give indications of
+# process resource usage
+
+rusage = None
+PAGE_SIZE = getpagesize()
+
+def update_resource_metrics():
+    global rusage
+    rusage = getrusage(RUSAGE_SELF)
+
+resource_metrics = get_metrics_for("process.resource")
+
+# msecs
+resource_metrics.register_callback("utime", lambda: rusage.ru_utime * 1000)
+resource_metrics.register_callback("stime", lambda: rusage.ru_stime * 1000)
+
+# pages
+resource_metrics.register_callback("maxrss", lambda: rusage.ru_maxrss * PAGE_SIZE)