summary refs log tree commit diff
path: root/synapse
diff options
context:
space:
mode:
authorPaul "LeoNerd" Evans <paul@matrix.org>2016-10-19 15:04:52 +0100
committerPaul "LeoNerd" Evans <paul@matrix.org>2016-10-19 15:05:22 +0100
commit981f852d540f20ff58c2ab0c2b59f42f89f01e61 (patch)
tree2853237d15f26dd8626fc5f4f60174592123a612 /synapse
parentAdd standard process_max_fds metric (diff)
downloadsynapse-981f852d540f20ff58c2ab0c2b59f42f89f01e61.tar.xz
Add standard process_start_time_seconds metric
Diffstat (limited to 'synapse')
-rw-r--r--synapse/metrics/__init__.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/synapse/metrics/__init__.py b/synapse/metrics/__init__.py
index 75ba248c56..a79fb026d4 100644
--- a/synapse/metrics/__init__.py
+++ b/synapse/metrics/__init__.py
@@ -119,6 +119,17 @@ rusage = None
 stats = None
 fd_counts = None
 
+# In order to report process_start_time_seconds we need to know the machine's
+# boot time, because the value in /proc/self/stat is relative to this
+boot_time = None
+try:
+    with open("/proc/stat") as _procstat:
+        for line in _procstat:
+            if line.startswith("btime "):
+                boot_time = int(line.split()[1])
+except IOError:
+    pass
+
 TYPES = {
     stat.S_IFSOCK: "SOCK",
     stat.S_IFLNK: "LNK",
@@ -218,6 +229,10 @@ process_metrics.register_callback(
     "max_fds", lambda: _get_max_fds()
 )
 
+process_metrics.register_callback(
+    "start_time_seconds", lambda: boot_time + int(stats[19]) / TICKS_PER_SEC
+)
+
 reactor_metrics = get_metrics_for("reactor")
 tick_time = reactor_metrics.register_distribution("tick_time")
 pending_calls_metric = reactor_metrics.register_distribution("pending_calls")