diff --git a/openstack_tools/cmd/prometheus/routers_l3_ha.py b/openstack_tools/cmd/prometheus/routers_l3_ha.py index 0d1efd1..7887ca1 100644 --- a/openstack_tools/cmd/prometheus/routers_l3_ha.py +++ b/openstack_tools/cmd/prometheus/routers_l3_ha.py @@ -83,6 +83,11 @@ def main(): while True: output = "" for pid_file in get_pid_files(args.state): + state_path = pid_file.replace('.pid.keepalived-vrrp', '') + state_file = os.path.join(state_path, 'state') + + router_id = os.path.basename(state_path) + with open(pid_file) as pid_fd: pid = int(pid_fd.read()) @@ -90,10 +95,12 @@ def main(): if psutil.pid_exists(pid) is False: continue - state_path = pid_file.replace('.pid.keepalived-vrrp', '') - state_file = os.path.join(state_path, 'state') + # Check if the PID is indeed for the correct router + proc = psutil.Process(pid) + cmdline = " ".join(proc.cmdline()) + if router_id not in cmdline: + continue - router_id = os.path.basename(state_path) with open(state_file) as state_fd: master = 1 if 'master' in state_fd.read() else 0