diff --git a/neutron/templates/bin/_health-probe.py.tpl b/neutron/templates/bin/_health-probe.py.tpl index f242b8b3a6..d5cfbae8cf 100644 --- a/neutron/templates/bin/_health-probe.py.tpl +++ b/neutron/templates/bin/_health-probe.py.tpl @@ -148,25 +148,26 @@ 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: - if parentId == 0: - parentId = p.pid - else: - if p.ppid() == parentId: - continue - pcon = p.connections() - for con in pcon: - try: - port = con.raddr[1] - status = con.status - except IndexError: - continue - if port in rabbitmq_ports and status == tcp_established: - rabbit_sock_count = rabbit_sock_count + 1 - except psutil.NoSuchProcess: + with p.oneshot(): + if proc in " ".join(p.cmdline()): + if parentId == 0: + parentId = p.pid + else: + if p.ppid() == parentId: + continue + pcon = p.connections() + for con in pcon: + try: + port = con.raddr[1] + status = con.status + except IndexError: + continue + if port in rabbitmq_ports and\ + status == tcp_established: + rabbit_sock_count = rabbit_sock_count + 1 + except psutil.Error: continue if rabbit_sock_count == 0: diff --git a/nova/templates/bin/_health-probe.py.tpl b/nova/templates/bin/_health-probe.py.tpl index b0c1095fe4..423326361f 100644 --- a/nova/templates/bin/_health-probe.py.tpl +++ b/nova/templates/bin/_health-probe.py.tpl @@ -90,25 +90,26 @@ 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: - if parentId == 0: - parentId = p.pid - else: - if p.ppid() == parentId and not cfg.CONF.check_all_pids: - continue - pcon = p.connections() - for con in pcon: - try: - rport = con.raddr[1] - status = con.status - except IndexError: - continue - if rport in ports and status == tcp_established: - sock_count = sock_count + 1 - except psutil.NoSuchProcess: + 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: + continue + pcon = p.connections() + for con in pcon: + try: + rport = con.raddr[1] + status = con.status + except IndexError: + continue + if rport in ports and status == tcp_established: + sock_count = sock_count + 1 + except psutil.Error: continue if sock_count == 0: