Fairly viable aloe state

This commit is contained in:
Reid 'arrdem' McKenzie 2021-12-12 21:36:21 -07:00
parent 3e4d02f2f4
commit 37435f6423
2 changed files with 16 additions and 16 deletions

View file

@ -137,29 +137,29 @@ def retrace(shutdown, q, opts, hl, hosts):
threads = {}
def create_host(distance, address):
with hl:
if address not in hosts:
log.info(f"Monitoring {address}...")
with hl:
hosts[(distance, address)] = monitor = MonitoredHost(address, timedelta(seconds=8))
threads[(distance, address)] = t = Thread(target=monitor, args=(shutdown, q))
monitor = MonitoredHost(address, timedelta(seconds=1))
hosts[address] = (distance, monitor)
threads[address] = t = Thread(target=monitor, args=(shutdown, q))
t.start()
else:
log.debug(f"Already monitoring {address}...")
while not shutdown.is_set():
for h in opts.hosts:
# 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:
create_host(distance, hop.address)
create_host(hop.distance, hop.address)
sleep(shutdown, 60 * 5)
def render(shutdown, q, stdscr, hl, hosts):
dt = timedelta(seconds=8)
dt = timedelta(minutes=30)
with open("incidents.txt", "w") as fp:
incident = False
@ -169,7 +169,7 @@ def render(shutdown, q, stdscr, hl, hosts):
now = datetime.now()
i = 0
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
state = host.state.last()
if not state:

View file

@ -95,7 +95,7 @@ def icmp_worker(shutdown: Event, q: queue.Queue):
while not shutdown.is_set():
# Send one
try:
item = q.get(block=False, timeout=0.1)
item = q.get(block=False, timeout=0.001)
request = item._request
state[(request._id, request._sequence)] = item
# log.info(f"Sending request {item._request!r}")
@ -105,7 +105,7 @@ def icmp_worker(shutdown: Event, q: queue.Queue):
# Recieve one
try:
if response := sock.receive(None, 0.1):
if response := sock.receive(None, 0.001):
key = (response.id, response.sequence)
if key in state:
# log.info(f"Got response {response!r}")
@ -123,7 +123,7 @@ def icmp_worker(shutdown: Event, q: queue.Queue):
del state[key]
# Sleep one
sleep(shutdown, 0.1)
sleep(shutdown, 0.001)
def traceroute(q: queue.Queue,