monasca_setup:to speedup detection, ask only for needed data for process

`as_dict` tries to retrieve various params of process from the OS which
are time consuming to obtain and not required for the filtering being
performed.

Change-Id: If02f6703b17b02e36797aa23417ea55fdaea89e2
Story: 2001004
Task: 4187
This commit is contained in:
Sumit Jamgade 2017-04-25 09:23:41 +02:00
parent 96b91896e7
commit 08441ec586
4 changed files with 8 additions and 8 deletions

View File

@ -45,7 +45,7 @@ def _get_impl_lang(process):
:rtype: str
"""
p_exe = process.as_dict()['exe']
p_exe = process.as_dict(['exe'])['exe']
for lm in _PYTHON_LANG_MARKERS:
if lm in p_exe:
return 'python'
@ -111,7 +111,7 @@ class MonAPI(monasca_setup.detection.Plugin):
"""
p_exe = process.as_dict()['exe']
p_exe = process.as_dict(['exe'])['exe']
for m in _APACHE_MARKERS:
if m in p_exe:
return process.parent()
@ -128,7 +128,7 @@ class MonAPI(monasca_setup.detection.Plugin):
log.info('\tmonasca-api runs under Apache WSGI')
api_process = apache_process
impl_helper = self._init_impl_helper(api_process.as_dict()['cmdline'],
impl_helper = self._init_impl_helper(api_process.as_dict(['cmdline'])['cmdline'],
impl_lang)
impl_helper.load_configuration()
@ -218,7 +218,7 @@ class MonPersister(monasca_setup.detection.Plugin):
if process_found:
impl_lang = _get_impl_lang(p_process)
impl_helper = self._init_impl_helper(
p_process.as_dict()['cmdline'],
p_process.as_dict(['cmdline'])['cmdline'],
impl_lang
)

View File

@ -35,7 +35,7 @@ def find_process_cmdline(search_string):
"""
for process in psutil.process_iter():
try:
process_cmdline = ' '.join(process.as_dict()['cmdline'])
process_cmdline = ' '.join(process.as_dict(['cmdline'])['cmdline'])
if (search_string in process_cmdline and
'monasca-setup' not in process_cmdline):
return process
@ -50,7 +50,7 @@ def find_process_name(pname):
"""
for process in psutil.process_iter():
try:
if pname == process.as_dict()['name']:
if pname == process.as_dict(['name'])['name']:
return process
except psutil.NoSuchProcess:
continue

View File

@ -44,7 +44,7 @@ class JsonResponse(object):
class PSUtilGetProc(object):
cmdLine = ['kibana']
def as_dict(self):
def as_dict(self, attrs=None):
return {'name': 'kibana',
'cmdline': PSUtilGetProc.cmdLine}

View File

@ -101,7 +101,7 @@ class FakeProcesses(object):
FakeInetConnection()
]
def as_dict(self):
def as_dict(self, attrs=None):
return {'name': FakeProcesses.name,
'cmdline': FakeProcesses.cmdLine,
'exe': self.exe()}