manager consider whether ovpn interface is up

This commit is contained in:
mantaohuang 2020-08-02 00:17:22 -04:00
parent 059085a1f0
commit c1e9f7ab59
2 changed files with 6 additions and 1 deletions

View File

@ -284,7 +284,7 @@ class OManager:
# n_down = 2
weights = []
for i in self.instances:
if i["op"].status != RUNNING:
if i["op"].status != RUNNING or (not i["op"].interface_up):
i["weight"] = 0
weights.append(i["weight"])
continue

View File

@ -78,6 +78,7 @@ class Openvpn:
self.loop = loop
else:
self.loop = asyncio.get_event_loop()
self.interface_up = False
self.load_cfg(ovpn_config, env_config)
def load_cfg(self, ovpn_config, env_config):
@ -223,6 +224,7 @@ class Openvpn:
for task in self.run_task:
task.cancel()
self.run_task = []
self.interface_up = False
if clear_folder:
self.clear_folder()
@ -275,8 +277,11 @@ class Openvpn:
"""
io_count = psutil.net_io_counters(pernic=True)
if self.interface not in io_count:
self.interface_up = False
logging.debug(f"interface {self.interface} is not ready.")
return
self.monitor_interval = True
io_count = io_count[self.interface]
open(self.io_stat_fp, "a").write(
f"{datetime.utcnow().timestamp()},{io_count.bytes_recv},{io_count.bytes_sent}\n")