Merge "Fix psutil inconsistencies"

This commit is contained in:
Zuul
2019-10-10 14:51:52 +00:00
committed by Gerrit Code Review
2 changed files with 38 additions and 36 deletions

View File

@@ -148,10 +148,10 @@ def tcp_socket_state_check(agentq):
rabbitmq_ports = get_rabbitmq_ports()
for pr in psutil.pids():
for p in psutil.process_iter():
try:
p = psutil.Process(pr)
if p.name() == proc:
with p.oneshot():
if proc in " ".join(p.cmdline()):
if parentId == 0:
parentId = p.pid
else:
@@ -164,9 +164,10 @@ def tcp_socket_state_check(agentq):
status = con.status
except IndexError:
continue
if port in rabbitmq_ports and status == tcp_established:
if port in rabbitmq_ports and\
status == tcp_established:
rabbit_sock_count = rabbit_sock_count + 1
except psutil.NoSuchProcess:
except psutil.Error:
continue
if rabbit_sock_count == 0:

View File

@@ -90,14 +90,15 @@ def tcp_socket_status(process, ports):
"""Check the tcp socket status on a process"""
sock_count = 0
parentId = 0
for pr in psutil.pids():
for p in psutil.process_iter():
try:
p = psutil.Process(pr)
if p.name() == process:
with p.oneshot():
if process in " ".join(p.cmdline()):
if parentId == 0:
parentId = p.pid
else:
if p.ppid() == parentId and not cfg.CONF.check_all_pids:
if p.ppid() == parentId and \
not cfg.CONF.check_all_pids:
continue
pcon = p.connections()
for con in pcon:
@@ -108,7 +109,7 @@ def tcp_socket_status(process, ports):
continue
if rport in ports and status == tcp_established:
sock_count = sock_count + 1
except psutil.NoSuchProcess:
except psutil.Error:
continue
if sock_count == 0: