Merge "Fixes process checker using older psutil versions"

This commit is contained in:
Jenkins 2016-10-21 22:35:41 +00:00 committed by Gerrit Code Review
commit 1544d4cb49
3 changed files with 22 additions and 14 deletions

View File

@ -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:

View File

@ -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

View File

@ -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