[nyx/master] Merge heartbeat_check() into header panel
commit 2013e771145df9ee845e4098011e308cafeb55d7 Author: Damian Johnson <atagar@torproject.org> Date: Wed Feb 10 19:35:20 2016 -0800 Merge heartbeat_check() into header panel Our header panel already provides notices for file descriptor usage. Heartbeat tracking is pretty similar. --- nyx/controller.py | 25 ------------------------- nyx/header_panel.py | 14 ++++++++++++-- 2 files changed, 12 insertions(+), 27 deletions(-) diff --git a/nyx/controller.py b/nyx/controller.py index 07cab4d..0f972b3 100644 --- a/nyx/controller.py +++ b/nyx/controller.py @@ -400,29 +400,6 @@ class Controller: self.quit_signal = True -def heartbeat_check(is_unresponsive): - """ - Logs if its been ten seconds since the last BW event. - - Arguments: - is_unresponsive - flag for if we've indicated to be responsive or not - """ - - controller = tor_controller() - last_heartbeat = controller.get_latest_heartbeat() - - if controller.is_alive(): - if not is_unresponsive and (time.time() - last_heartbeat) >= 10: - is_unresponsive = True - log.notice('Relay unresponsive (last heartbeat: %s)' % time.ctime(last_heartbeat)) - elif is_unresponsive and (time.time() - last_heartbeat) < 10: - # really shouldn't happen (meant Tor froze for a bit) - is_unresponsive = False - log.notice('Relay resumed') - - return is_unresponsive - - def start_nyx(stdscr): """ Main draw loop context. @@ -469,11 +446,9 @@ def start_nyx(stdscr): # main draw loop override_key = None # uses this rather than waiting on user input - is_unresponsive = False # flag for heartbeat responsiveness check while not control.quit_signal: display_panels = control.get_display_panels() - is_unresponsive = heartbeat_check(is_unresponsive) # sets panel visability diff --git a/nyx/header_panel.py b/nyx/header_panel.py index 4a0841e..bbc5ede 100644 --- a/nyx/header_panel.py +++ b/nyx/header_panel.py @@ -43,6 +43,7 @@ class HeaderPanel(panel.Panel, threading.Thread): self._pause_condition = threading.Condition() self._halt = False # terminates thread if true + self._reported_inactive = False tor_controller().add_status_listener(self.reset_listener) @@ -217,7 +218,8 @@ class HeaderPanel(panel.Panel, threading.Thread): """ x = self.addstr(y, x, 'Tor Disconnected', curses.A_BOLD, 'red') - self.addstr(y, x, vals.format(' ({last_heartbeat}, press r to reconnect)')) + last_heartbeat = time.strftime('%H:%M %m/%d/%Y', time.localtime(vals.last_heartbeat)) + self.addstr(y, x, ' (%s, press r to reconnect)' % last_heartbeat) def _draw_resource_usage(self, x, y, width, vals): """ @@ -388,6 +390,14 @@ class HeaderPanel(panel.Panel, threading.Thread): log_msg = msg('panel.header.fd_used_at_sixty_percent', percentage = fd_percent) log.log_once('fd_used_at_sixty_percent', log.NOTICE, log_msg) + if self._vals.is_connected: + if not self._reported_inactive and (time.time() - self._vals.last_heartbeat) >= 10: + self._reported_inactive = True + log.notice('Relay unresponsive (last heartbeat: %s)' % time.ctime(self._vals.last_heartbeat)) + elif self._reported_inactive and (time.time() - self._vals.last_heartbeat) < 10: + self._reported_inactive = False + log.notice('Relay resumed') + if previous_height != self.get_height(): # We're toggling between being a relay and client, causing the height # of this panel to change. Redraw all content so we don't get @@ -436,7 +446,7 @@ def get_sampling(last_sampling = None): 'retrieved': retrieved, 'is_connected': controller.is_alive(), 'connection_time': controller.connection_time(), - 'last_heartbeat': time.strftime('%H:%M %m/%d/%Y', time.localtime(controller.get_latest_heartbeat())), + 'last_heartbeat': controller.get_latest_heartbeat(), 'fingerprint': controller.get_info('fingerprint', 'Unknown'), 'nickname': controller.get_conf('Nickname', ''),
participants (1)
-
atagar@torproject.org