Forgot some locks. Sigh.
This commit is contained in:
parent
7344d858c6
commit
c4f13f186a
1 changed files with 32 additions and 28 deletions
|
@ -43,6 +43,7 @@ class HostState(object):
|
|||
is_up: bool = False,
|
||||
lost: int = 0,
|
||||
up: float = 0.0):
|
||||
self._lock = Lock()
|
||||
self._state = ringbuffer(maxlen=history_size)
|
||||
self._is_up = is_up
|
||||
self._lost = lost
|
||||
|
@ -52,6 +53,7 @@ class HostState(object):
|
|||
self.append(resp)
|
||||
|
||||
def append(self, resp):
|
||||
with self._lock:
|
||||
if resp and not self._is_up:
|
||||
# log.debug(f"Host {self._hostname} is up!")
|
||||
self._is_up = self._is_up or resp
|
||||
|
@ -78,9 +80,11 @@ class HostState(object):
|
|||
self._state.append(resp)
|
||||
|
||||
def last(self):
|
||||
with self._lock:
|
||||
return next(reversed(self._state), None)
|
||||
|
||||
def last_window(self, duration: timedelta = None):
|
||||
with self._lock:
|
||||
l = []
|
||||
t = time() - duration.total_seconds()
|
||||
for i in reversed(self._state):
|
||||
|
@ -140,7 +144,7 @@ def retrace(shutdown, q, opts, hl, hosts):
|
|||
with hl:
|
||||
if address not in hosts:
|
||||
log.info(f"Monitoring {address}...")
|
||||
monitor = MonitoredHost(address, timedelta(seconds=1))
|
||||
monitor = MonitoredHost(address, timedelta(seconds=2))
|
||||
hosts[address] = (distance, monitor)
|
||||
threads[address] = t = Thread(target=monitor, args=(shutdown, q))
|
||||
t.start()
|
||||
|
|
Loading…
Reference in a new issue