def __init__(self, window, ip, nap): Thread.__init__(self) self._window = window self._ip = ip self._nap = nap maxlen = int(math.ceil(SECONDS * POINTS_PER_SECONDS)) self._samples_down = deque(maxlen=maxlen) self._samples_up = deque(maxlen=maxlen) for i in range (0, maxlen): self._samples_down.append(0) self._samples_up.append(0) self._p = Pcapper(self._ip) self._p.start()
class Updater(Thread): def __init__(self, window, ip, nap): Thread.__init__(self) self._window = window self._ip = ip self._nap = nap maxlen = int(math.ceil(SECONDS * POINTS_PER_SECONDS)) self._samples_down = deque(maxlen=maxlen) self._samples_up = deque(maxlen=maxlen) for i in range (0, maxlen): self._samples_down.append(0) self._samples_up.append(0) self._p = Pcapper(self._ip) self._p.start() def _get_sample(self): self._p.sniff(Contabyte(self._ip, self._nap)) time.sleep(SAMPLE_INTERVAL) self._p.stop_sniff() stats = self._p.get_stats() down = stats.byte_down_all_net * 8.0 / (SAMPLE_INTERVAL * 1000.0) up = -stats.byte_up_all_net * 8.0 / (SAMPLE_INTERVAL * 1000.0) return (down, up) def _update_samples(self): (down, up) = self._get_sample() self._samples_down.popleft() self._samples_down.append(down) self._samples_up.popleft() self._samples_up.append(up) def run(self): while(self._window): try: self._update_samples() wx.CallAfter(self._window.Plot_Data, list(self._samples_down), list(self._samples_up)) time.sleep(1.0 / POINTS_PER_SECONDS - SAMPLE_INTERVAL) except: break self._p.stop() self._p.join() def stop(self): self._window = None