summary refs log tree commit diff
path: root/synapse/metrics
diff options
context:
space:
mode:
authorPaul "LeoNerd" Evans <paul@matrix.org>2015-03-05 16:15:21 +0000
committerPaul "LeoNerd" Evans <paul@matrix.org>2015-03-12 16:24:51 +0000
commit399689dcc79e73de1ec6bae8aa18bd83f5618f38 (patch)
tree1657827bb6b796f91900bdf91e0659a3488c3a22 /synapse/metrics
parentAdd TimerMetrics to shadow the PerformanceCounters in synapse.storage; with t... (diff)
downloadsynapse-399689dcc79e73de1ec6bae8aa18bd83f5618f38.tar.xz
Provide some process resource usage metrics
Diffstat (limited to 'synapse/metrics')
-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)