manager consider whether ovpn interface is up
This commit is contained in:
parent
059085a1f0
commit
c1e9f7ab59
@ -284,7 +284,7 @@ class OManager:
|
|||||||
# n_down = 2
|
# n_down = 2
|
||||||
weights = []
|
weights = []
|
||||||
for i in self.instances:
|
for i in self.instances:
|
||||||
if i["op"].status != RUNNING:
|
if i["op"].status != RUNNING or (not i["op"].interface_up):
|
||||||
i["weight"] = 0
|
i["weight"] = 0
|
||||||
weights.append(i["weight"])
|
weights.append(i["weight"])
|
||||||
continue
|
continue
|
||||||
|
|||||||
@ -78,6 +78,7 @@ class Openvpn:
|
|||||||
self.loop = loop
|
self.loop = loop
|
||||||
else:
|
else:
|
||||||
self.loop = asyncio.get_event_loop()
|
self.loop = asyncio.get_event_loop()
|
||||||
|
self.interface_up = False
|
||||||
self.load_cfg(ovpn_config, env_config)
|
self.load_cfg(ovpn_config, env_config)
|
||||||
|
|
||||||
def load_cfg(self, ovpn_config, env_config):
|
def load_cfg(self, ovpn_config, env_config):
|
||||||
@ -223,6 +224,7 @@ class Openvpn:
|
|||||||
for task in self.run_task:
|
for task in self.run_task:
|
||||||
task.cancel()
|
task.cancel()
|
||||||
self.run_task = []
|
self.run_task = []
|
||||||
|
self.interface_up = False
|
||||||
if clear_folder:
|
if clear_folder:
|
||||||
self.clear_folder()
|
self.clear_folder()
|
||||||
|
|
||||||
@ -275,8 +277,11 @@ class Openvpn:
|
|||||||
"""
|
"""
|
||||||
io_count = psutil.net_io_counters(pernic=True)
|
io_count = psutil.net_io_counters(pernic=True)
|
||||||
if self.interface not in io_count:
|
if self.interface not in io_count:
|
||||||
|
self.interface_up = False
|
||||||
logging.debug(f"interface {self.interface} is not ready.")
|
logging.debug(f"interface {self.interface} is not ready.")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
self.monitor_interval = True
|
||||||
io_count = io_count[self.interface]
|
io_count = io_count[self.interface]
|
||||||
open(self.io_stat_fp, "a").write(
|
open(self.io_stat_fp, "a").write(
|
||||||
f"{datetime.utcnow().timestamp()},{io_count.bytes_recv},{io_count.bytes_sent}\n")
|
f"{datetime.utcnow().timestamp()},{io_count.bytes_recv},{io_count.bytes_sent}\n")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user