mirror of
https://mau.dev/maunium/synapse.git
synced 2024-12-14 09:33:53 +01:00
Merge pull request #992 from matrix-org/erikj/psutil_conditional
Make psutil optional
This commit is contained in:
commit
e7674eb759
3 changed files with 16 additions and 6 deletions
|
@ -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):
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -36,7 +36,6 @@ REQUIREMENTS = {
|
|||
"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": {
|
||||
|
@ -52,6 +51,9 @@ CONDITIONAL_REQUIREMENTS = {
|
|||
"ldap": {
|
||||
"ldap3>=1.0": ["ldap3>=1.0"],
|
||||
},
|
||||
"psutil": {
|
||||
"psutil>=2.0.0": ["psutil>=2.0.0"],
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue