summary refs log tree commit diff
path: root/synapse/metrics/__init__.py
diff options
context:
space:
mode:
authorAmber Brown <hawkowl@atleastfornow.net>2018-05-23 13:03:56 -0500
committerAmber Brown <hawkowl@atleastfornow.net>2018-05-23 13:03:56 -0500
commit472a5ec4e208967aaf1368ada321aa54c3cae493 (patch)
treeaa036fb32bf3fcca64301f0f943e8914fa00a700 /synapse/metrics/__init__.py
parentfixes (diff)
downloadsynapse-472a5ec4e208967aaf1368ada321aa54c3cae493.tar.xz
add back CPU metrics
Diffstat (limited to 'synapse/metrics/__init__.py')
-rw-r--r--synapse/metrics/__init__.py36
1 files changed, 35 insertions, 1 deletions
diff --git a/synapse/metrics/__init__.py b/synapse/metrics/__init__.py
index 75117915ff..64ad762ff1 100644
--- a/synapse/metrics/__init__.py
+++ b/synapse/metrics/__init__.py
@@ -17,6 +17,7 @@ import logging
 import functools
 import time
 import gc
+import os
 import platform
 import attr
 
@@ -82,6 +83,38 @@ class LaterGauge(object):
 
 
 #
+# Detailed CPU metrics
+#
+
+class CPUMetrics(object):
+
+    def __init__(self):
+        ticks_per_sec = 100
+        try:
+            # Try and get the system config
+            ticks_per_sec = os.sysconf('SC_CLK_TCK')
+        except (ValueError, TypeError, AttributeError):
+            pass
+
+        self.ticks_per_sec = ticks_per_sec
+
+    def collect(self):
+
+        with open("/proc/self/stat") as s:
+            line = s.read()
+            raw_stats = line.split(") ", 1)[1].split(" ")
+
+            user = GaugeMetricFamily("process_cpu_user_seconds_total", "")
+            user.add_metric([], float(raw_stats[11]) / self.ticks_per_sec)
+            yield user
+
+            sys = GaugeMetricFamily("process_cpu_system_seconds_total", "")
+            sys.add_metric([], float(raw_stats[12]) / self.ticks_per_sec)
+            yield sys
+
+REGISTRY.register(CPUMetrics())
+
+#
 # Python GC metrics
 #
 
@@ -90,7 +123,8 @@ gc_time = Histogram(
     "python_gc_time",
     "Time taken to GC (ms)",
     ["gen"],
-    buckets=[1, 2, 5, 10, 25, 50, 100, 250, 500, 1000],
+    buckets=[2.5, 5, 10, 25, 50, 100, 250, 500, 1000, 2500, 5000, 7500, 15000,
+             30000, 45000, 60000],
 )