diff options
author | Erik Johnston <erik@matrix.org> | 2016-08-08 11:24:53 +0100 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2016-08-08 11:24:53 +0100 |
commit | 34101427417f58418a9587adfeca3d41898b5e24 (patch) | |
tree | f1cb2f39d3838b1dcf709c3f3921dbe82afdd3a5 /synapse/metrics | |
parent | Update changelog (diff) | |
parent | Merge pull request #992 from matrix-org/erikj/psutil_conditional (diff) | |
download | synapse-34101427417f58418a9587adfeca3d41898b5e24.tar.xz |
Merge branch 'develop' of github.com:matrix-org/synapse into release-v0.17.0
Diffstat (limited to 'synapse/metrics')
-rw-r--r-- | synapse/metrics/__init__.py | 13 | ||||
-rw-r--r-- | synapse/metrics/metric.py | 5 |
2 files changed, 13 insertions, 5 deletions
diff --git a/synapse/metrics/__init__.py b/synapse/metrics/__init__.py index cce3dba47c..76d5998d75 100644 --- a/synapse/metrics/__init__.py +++ b/synapse/metrics/__init__.py @@ -68,9 +68,18 @@ class Metrics(object): def register_memory_metrics(hs): - metric = MemoryUsageMetric(hs) + try: + import psutil + process = psutil.Process() + process.memory_info().rss + except (ImportError, AttributeError): + logger.warn( + "psutil is not installed or incorrect version." + " Disabling memory metrics." + ) + return + metric = MemoryUsageMetric(hs, psutil) all_metrics.append(metric) - return metric def get_metrics_for(pkg_name): diff --git a/synapse/metrics/metric.py b/synapse/metrics/metric.py index 7becbe0491..e81af29895 100644 --- a/synapse/metrics/metric.py +++ b/synapse/metrics/metric.py @@ -16,8 +16,6 @@ from itertools import chain -import psutil - # TODO(paul): I can't believe Python doesn't have one of these def map_concat(func, items): @@ -167,9 +165,10 @@ class MemoryUsageMetric(object): UPDATE_HZ = 2 # number of times to get memory per second WINDOW_SIZE_SEC = 30 # the size of the window in seconds - def __init__(self, hs): + def __init__(self, hs, psutil): clock = hs.get_clock() self.memory_snapshots = [] + self.process = psutil.Process() clock.looping_call(self._update_curr_values, 1000 / self.UPDATE_HZ) |