Merge "Fixes process checker using older psutil versions"
This commit is contained in:
commit
1544d4cb49
@ -151,17 +151,20 @@ class ProcessCheck(checks.AgentCheck):
|
|||||||
|
|
||||||
for process in psutil.process_iter():
|
for process in psutil.process_iter():
|
||||||
try:
|
try:
|
||||||
p = ProcessStruct(name=process.name(),
|
process_dict = process.as_dict(
|
||||||
pid=process.pid,
|
attrs=['name', 'pid', 'username', 'cmdline'])
|
||||||
username=process.username(),
|
p = ProcessStruct(name=process_dict['name'],
|
||||||
cmdline=' '.join(process.cmdline()))
|
pid=process_dict['pid'],
|
||||||
|
username=process_dict['username'],
|
||||||
|
cmdline=' '.join(process_dict['cmdline']))
|
||||||
self._current_process_list.append(p)
|
self._current_process_list.append(p)
|
||||||
except psutil.NoSuchProcess:
|
except psutil.NoSuchProcess:
|
||||||
# No way to log useful information here so just move on
|
# No way to log useful information here so just move on
|
||||||
pass
|
pass
|
||||||
except psutil.AccessDenied as e:
|
except psutil.AccessDenied as e:
|
||||||
|
process_dict = process.as_dict(attrs=['name'])
|
||||||
self.log.info('Access denied to process {0}: {1}'.format(
|
self.log.info('Access denied to process {0}: {1}'.format(
|
||||||
process.name(), e))
|
process_dict['name'], e))
|
||||||
|
|
||||||
def check(self, instance):
|
def check(self, instance):
|
||||||
try:
|
try:
|
||||||
|
@ -11,7 +11,7 @@ gevent>=1.1.1
|
|||||||
httplib2>=0.7.5,<=0.9.2
|
httplib2>=0.7.5,<=0.9.2
|
||||||
netaddr>=0.7.12,<=0.7.18,!=0.7.16
|
netaddr>=0.7.12,<=0.7.18,!=0.7.16
|
||||||
ntplib>=0.3.2,<0.4
|
ntplib>=0.3.2,<0.4
|
||||||
psutil>=3.0.0,<3.1.0
|
psutil<3.1.0
|
||||||
pymongo>=3.0.2,<=3.2.2,!=3.1
|
pymongo>=3.0.2,<=3.2.2,!=3.1
|
||||||
python-memcached>=1.56,<=1.58
|
python-memcached>=1.56,<=1.58
|
||||||
python-monascaclient>=1.0.30 # Apache-2.0
|
python-monascaclient>=1.0.30 # Apache-2.0
|
||||||
|
@ -11,12 +11,13 @@ class TestSimpleProcess(unittest.TestCase):
|
|||||||
self.mock_process_iter = self.psutil_process_iter_patcher.start()
|
self.mock_process_iter = self.psutil_process_iter_patcher.start()
|
||||||
|
|
||||||
process_attrs = {
|
process_attrs = {
|
||||||
'name.return_value': 'process_name',
|
'name': 'process_name',
|
||||||
'pid': 1234,
|
'pid': 1234,
|
||||||
'username.return_value': 'user',
|
'username': 'user',
|
||||||
'cmdline.return_value': '/usr/bin/process_name'
|
'cmdline': '/usr/bin/process_name'
|
||||||
}
|
}
|
||||||
process = mock.Mock(**process_attrs)
|
process = mock.Mock()
|
||||||
|
process.as_dict.return_value = process_attrs
|
||||||
self.mock_process_iter.return_value = [process]
|
self.mock_process_iter.return_value = [process]
|
||||||
|
|
||||||
config = {'init_config': {},
|
config = {'init_config': {},
|
||||||
@ -44,11 +45,14 @@ class TestDetailedProcess(unittest.TestCase):
|
|||||||
self.mock_process = self.psutil_process_patcher.start()
|
self.mock_process = self.psutil_process_patcher.start()
|
||||||
self.mock_process_iter = self.psutil_process_iter_patcher.start()
|
self.mock_process_iter = self.psutil_process_iter_patcher.start()
|
||||||
|
|
||||||
process_attrs = {
|
process_attrs_as_dict = {
|
||||||
'name.return_value': 'process_name',
|
'name': 'process_name',
|
||||||
'pid': 1234,
|
'pid': 1234,
|
||||||
'username.return_value': 'user',
|
'username': 'user',
|
||||||
'cmdline.return_value': '/usr/bin/process_name',
|
'cmdline': '/usr/bin/process_name',
|
||||||
|
}
|
||||||
|
|
||||||
|
process_attrs = {
|
||||||
'memory_info_ex.return_value': mock.Mock(rss=1048576),
|
'memory_info_ex.return_value': mock.Mock(rss=1048576),
|
||||||
'num_threads.return_value': 1,
|
'num_threads.return_value': 1,
|
||||||
'num_fds.return_value': 1,
|
'num_fds.return_value': 1,
|
||||||
@ -59,6 +63,7 @@ class TestDetailedProcess(unittest.TestCase):
|
|||||||
'write_bytes': 1024})
|
'write_bytes': 1024})
|
||||||
}
|
}
|
||||||
process = mock.Mock(**process_attrs)
|
process = mock.Mock(**process_attrs)
|
||||||
|
process.as_dict.return_value = process_attrs_as_dict
|
||||||
self.mock_process_iter.return_value = [process]
|
self.mock_process_iter.return_value = [process]
|
||||||
self.mock_process.return_value = process
|
self.mock_process.return_value = process
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user