[or-cvs] r19619: {arm} Added notice when relay's been silent for five seconds (base (arm/trunk/interface)

atagar at seul.org atagar at seul.org
Wed Jun 3 02:36:55 UTC 2009


Author: atagar
Date: 2009-06-02 22:36:55 -0400 (Tue, 02 Jun 2009)
New Revision: 19619

Modified:
   arm/trunk/interface/controller.py
   arm/trunk/interface/logPanel.py
Log:
Added notice when relay's been silent for five seconds (based on BW events so probably due to Tor being closed). Another idea by karsten.


Modified: arm/trunk/interface/controller.py
===================================================================
--- arm/trunk/interface/controller.py	2009-06-02 21:14:29 UTC (rev 19618)
+++ arm/trunk/interface/controller.py	2009-06-03 02:36:55 UTC (rev 19619)
@@ -24,12 +24,12 @@
 
 # mapping of panels to (height, start y), -1 if unlimited
 PANEL_INFO = {
-  "summary": (6, 0),          # top static content
-  "control": (1, 6),          # line for user input
-  "bandwidthLabel": (1, 7),   # bandwidth section label
-  "bandwidth": (8, 8),        # bandwidth measurements / graph
-  "logLabel": (1, 16),        # message log label
-  "log": (-1, 17)}            # uses all remaining space for message log
+  "summary":        (6, 0),     # top static content
+  "control":        (1, 6),     # line for user input
+  "bandwidthLabel": (1, 7),     # bandwidth section label
+  "bandwidth":      (8, 8),     # bandwidth measurements / graph
+  "logLabel":       (1, 16),    # message log label
+  "log":            (-1, 17)}   # uses all remaining space for message log
 
 def drawControlLabel(scr, msgType, arg=""):
   """ Draws single line label for interface controls. """
@@ -71,9 +71,11 @@
         
         # removes and notes problem
         loggedEvents.remove(eventType)
-        logListener.registerEvent("ARM-ERR", "Unsupported event type: %s" % eventType, "red")
+        logListener.monitor_event("WARN", "Unsupported event type: %s" % eventType)
       else:
         raise exc
+    except TorCtl.TorCtlClosed:
+      return []
   
   loggedEvents = list(loggedEvents)
   loggedEvents.sort() # alphabetizes
@@ -149,7 +151,8 @@
   loggedEvents = setEventListening(loggedEvents, conn, logListener)
   eventsListing = ", ".join(loggedEvents)
   oldY, oldX = -1, -1
-  isPaused = False
+  isUnresponsive = False    # true if it's been over five seconds since the last BW event (probably due to Tor closing)
+  isPaused = False          # if true updates are frozen
   
   while True:
     # tried only refreshing when the screen was resized but it caused a
@@ -174,6 +177,15 @@
       
       oldY, oldX = y, x
       stdscr.refresh()
+      
+      # if it's been at least five seconds since the last BW event Tor's probably done
+      if not isUnresponsive and logListener.getHeartbeat() >= 5:
+        isUnresponsive = True
+        logListener.monitor_event("NOTICE", "Relay unresponsive (last heartbeat: %s)" % time.ctime(logListener.lastHeartbeat))
+      elif isUnresponsive and logListener.getHeartbeat() < 5:
+        # this really shouldn't happen - BW events happen every second...
+        isUnresponsive = False
+        logListener.monitor_event("WARN", "Relay resumed")
     finally:
       cursesLock.release()
     

Modified: arm/trunk/interface/logPanel.py
===================================================================
--- arm/trunk/interface/logPanel.py	2009-06-02 21:14:29 UTC (rev 19618)
+++ arm/trunk/interface/logPanel.py	2009-06-03 02:36:55 UTC (rev 19619)
@@ -98,6 +98,7 @@
     self.pauseBuffer = []                 # location where messages are buffered if paused
     self.includeBW = includeBW            # true if we're supposed to listen for BW events
     self.includeUnknown = includeUnknown  # true if registering unrecognized events
+    self.lastHeartbeat = time.time()      # time of last BW event
   
   # Listens for all event types and redirects to registerEvent
   # TODO: not sure how to stimulate all event types - should be tried before
@@ -117,6 +118,7 @@
     self.registerEvent("STREAM_BW", "<STUB>", "white") # TODO: implement - variables: event.strm_id, event.bytes_read, event.bytes_written
   
   def bandwidth_event(self, event):
+    self.lastHeartbeat = time.time()
     if self.includeBW: self.registerEvent("BW", "READ: %i, WRITTEN: %i" % (event.read, event.written), "cyan")
   
   def msg_event(self, event):
@@ -137,6 +139,10 @@
   def unknown_event(self, event):
     if self.includeUnknown: self.registerEvent("UNKNOWN", event.event_string, "red")
   
+  def monitor_event(self, level, msg):
+    # events provided by the arm monitor - types use the same as runlevel
+    self.registerEvent("ARM-%s" % level, msg, RUNLEVEL_EVENT_COLOR[level])
+  
   def registerEvent(self, type, msg, color):
     """
     Notes event and redraws log. If paused it's held in a temporary buffer.
@@ -198,6 +204,13 @@
       self.msgLog = (self.pauseBuffer + self.msgLog)[:MAX_LOG_ENTRIES]
       self.refreshDisplay()
   
+  def getHeartbeat(self):
+    """
+    Provides the number of seconds since the last BW event.
+    """
+    
+    return time.time() - self.lastHeartbeat
+  
   # divides long message to cover two lines
   def _splitLine(self, message, x):
     # divides message into two lines, attempting to do it on a wordbreak



More information about the tor-commits mailing list