Merge pull request #992 from matrix-org/erikj/psutil_conditional
Make psutil optional
This commit is contained in:
commit
e7674eb759
|
@ -68,9 +68,18 @@ class Metrics(object):
|
||||||
|
|
||||||
|
|
||||||
def register_memory_metrics(hs):
|
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)
|
all_metrics.append(metric)
|
||||||
return metric
|
|
||||||
|
|
||||||
|
|
||||||
def get_metrics_for(pkg_name):
|
def get_metrics_for(pkg_name):
|
||||||
|
|
|
@ -16,8 +16,6 @@
|
||||||
|
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
|
|
||||||
import psutil
|
|
||||||
|
|
||||||
|
|
||||||
# TODO(paul): I can't believe Python doesn't have one of these
|
# TODO(paul): I can't believe Python doesn't have one of these
|
||||||
def map_concat(func, items):
|
def map_concat(func, items):
|
||||||
|
@ -167,9 +165,10 @@ class MemoryUsageMetric(object):
|
||||||
UPDATE_HZ = 2 # number of times to get memory per second
|
UPDATE_HZ = 2 # number of times to get memory per second
|
||||||
WINDOW_SIZE_SEC = 30 # the size of the window in seconds
|
WINDOW_SIZE_SEC = 30 # the size of the window in seconds
|
||||||
|
|
||||||
def __init__(self, hs):
|
def __init__(self, hs, psutil):
|
||||||
clock = hs.get_clock()
|
clock = hs.get_clock()
|
||||||
self.memory_snapshots = []
|
self.memory_snapshots = []
|
||||||
|
|
||||||
self.process = psutil.Process()
|
self.process = psutil.Process()
|
||||||
|
|
||||||
clock.looping_call(self._update_curr_values, 1000 / self.UPDATE_HZ)
|
clock.looping_call(self._update_curr_values, 1000 / self.UPDATE_HZ)
|
||||||
|
|
|
@ -36,7 +36,6 @@ REQUIREMENTS = {
|
||||||
"blist": ["blist"],
|
"blist": ["blist"],
|
||||||
"pysaml2>=3.0.0,<4.0.0": ["saml2>=3.0.0,<4.0.0"],
|
"pysaml2>=3.0.0,<4.0.0": ["saml2>=3.0.0,<4.0.0"],
|
||||||
"pymacaroons-pynacl": ["pymacaroons"],
|
"pymacaroons-pynacl": ["pymacaroons"],
|
||||||
"psutil>=2.0.0": ["psutil>=2.0.0"],
|
|
||||||
}
|
}
|
||||||
CONDITIONAL_REQUIREMENTS = {
|
CONDITIONAL_REQUIREMENTS = {
|
||||||
"web_client": {
|
"web_client": {
|
||||||
|
@ -52,6 +51,9 @@ CONDITIONAL_REQUIREMENTS = {
|
||||||
"ldap": {
|
"ldap": {
|
||||||
"ldap3>=1.0": ["ldap3>=1.0"],
|
"ldap3>=1.0": ["ldap3>=1.0"],
|
||||||
},
|
},
|
||||||
|
"psutil": {
|
||||||
|
"psutil>=2.0.0": ["psutil>=2.0.0"],
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue