Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #992 from matrix-org/erikj/psutil_conditional
Browse files Browse the repository at this point in the history
Make psutil optional
  • Loading branch information
erikjohnston authored Aug 8, 2016
2 parents f5deaff + 7c1a922 commit e7674eb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
13 changes: 11 additions & 2 deletions synapse/metrics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,18 @@ def register_cache(self, *args, **kwargs):


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):
Expand Down
5 changes: 2 additions & 3 deletions synapse/metrics/metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion synapse/python_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"blist": ["blist"],
"pysaml2>=3.0.0,<4.0.0": ["saml2>=3.0.0,<4.0.0"],
"pymacaroons-pynacl": ["pymacaroons"],
"psutil>=2.0.0": ["psutil>=2.0.0"],
}
CONDITIONAL_REQUIREMENTS = {
"web_client": {
Expand All @@ -52,6 +51,9 @@
"ldap": {
"ldap3>=1.0": ["ldap3>=1.0"],
},
"psutil": {
"psutil>=2.0.0": ["psutil>=2.0.0"],
},
}


Expand Down

0 comments on commit e7674eb

Please sign in to comment.