Fairly viable aloe state
This commit is contained in:
parent
3e4d02f2f4
commit
37435f6423
2 changed files with 16 additions and 16 deletions
|
@ -137,29 +137,29 @@ def retrace(shutdown, q, opts, hl, hosts):
|
||||||
threads = {}
|
threads = {}
|
||||||
|
|
||||||
def create_host(distance, address):
|
def create_host(distance, address):
|
||||||
|
with hl:
|
||||||
if address not in hosts:
|
if address not in hosts:
|
||||||
log.info(f"Monitoring {address}...")
|
log.info(f"Monitoring {address}...")
|
||||||
with hl:
|
monitor = MonitoredHost(address, timedelta(seconds=1))
|
||||||
hosts[(distance, address)] = monitor = MonitoredHost(address, timedelta(seconds=8))
|
hosts[address] = (distance, monitor)
|
||||||
threads[(distance, address)] = t = Thread(target=monitor, args=(shutdown, q))
|
threads[address] = t = Thread(target=monitor, args=(shutdown, q))
|
||||||
t.start()
|
t.start()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
log.debug(f"Already monitoring {address}...")
|
log.debug(f"Already monitoring {address}...")
|
||||||
|
|
||||||
|
|
||||||
while not shutdown.is_set():
|
while not shutdown.is_set():
|
||||||
for h in opts.hosts:
|
for h in opts.hosts:
|
||||||
# FIXME: Use a real topology model
|
# FIXME: Use a real topology model
|
||||||
for distance, hop in zip(count(1), traceroute(q, h)):
|
for hop in traceroute(q, h):
|
||||||
if ping(q, hop.address).is_alive:
|
if ping(q, hop.address).is_alive:
|
||||||
create_host(distance, hop.address)
|
create_host(hop.distance, hop.address)
|
||||||
|
|
||||||
sleep(shutdown, 60 * 5)
|
sleep(shutdown, 60 * 5)
|
||||||
|
|
||||||
|
|
||||||
def render(shutdown, q, stdscr, hl, hosts):
|
def render(shutdown, q, stdscr, hl, hosts):
|
||||||
dt = timedelta(seconds=8)
|
dt = timedelta(minutes=30)
|
||||||
|
|
||||||
with open("incidents.txt", "w") as fp:
|
with open("incidents.txt", "w") as fp:
|
||||||
incident = False
|
incident = False
|
||||||
|
@ -169,7 +169,7 @@ def render(shutdown, q, stdscr, hl, hosts):
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
i = 0
|
i = 0
|
||||||
with hl:
|
with hl:
|
||||||
for i, ((distance, name), host) in zip(count(1), sorted(hosts.items(), key=lambda x: x[0][0])):
|
for i, (name, (distance, host)) in zip(count(1), sorted(hosts.items(), key=lambda x: x[1][0])):
|
||||||
loss = host.state.loss(dt) * 100
|
loss = host.state.loss(dt) * 100
|
||||||
state = host.state.last()
|
state = host.state.last()
|
||||||
if not state:
|
if not state:
|
||||||
|
|
|
@ -95,7 +95,7 @@ def icmp_worker(shutdown: Event, q: queue.Queue):
|
||||||
while not shutdown.is_set():
|
while not shutdown.is_set():
|
||||||
# Send one
|
# Send one
|
||||||
try:
|
try:
|
||||||
item = q.get(block=False, timeout=0.1)
|
item = q.get(block=False, timeout=0.001)
|
||||||
request = item._request
|
request = item._request
|
||||||
state[(request._id, request._sequence)] = item
|
state[(request._id, request._sequence)] = item
|
||||||
# log.info(f"Sending request {item._request!r}")
|
# log.info(f"Sending request {item._request!r}")
|
||||||
|
@ -105,7 +105,7 @@ def icmp_worker(shutdown: Event, q: queue.Queue):
|
||||||
|
|
||||||
# Recieve one
|
# Recieve one
|
||||||
try:
|
try:
|
||||||
if response := sock.receive(None, 0.1):
|
if response := sock.receive(None, 0.001):
|
||||||
key = (response.id, response.sequence)
|
key = (response.id, response.sequence)
|
||||||
if key in state:
|
if key in state:
|
||||||
# log.info(f"Got response {response!r}")
|
# log.info(f"Got response {response!r}")
|
||||||
|
@ -123,7 +123,7 @@ def icmp_worker(shutdown: Event, q: queue.Queue):
|
||||||
del state[key]
|
del state[key]
|
||||||
|
|
||||||
# Sleep one
|
# Sleep one
|
||||||
sleep(shutdown, 0.1)
|
sleep(shutdown, 0.001)
|
||||||
|
|
||||||
|
|
||||||
def traceroute(q: queue.Queue,
|
def traceroute(q: queue.Queue,
|
||||||
|
|
Loading…
Reference in a new issue