[tor-commits] [arm/master] Revising ConnectionStats class

atagar at torproject.org atagar at torproject.org
Tue Oct 21 15:36:05 UTC 2014


commit 7b3830cee45711a69a8473ca4f4b7d35852c7f68
Author: Damian Johnson <atagar at torproject.org>
Date:   Tue Oct 21 08:24:00 2014 -0700

    Revising ConnectionStats class
    
    Nothing much. Minor rename of the class, tweaks to the code. Only functional
    difference is that we now won't cause a stacktrace if our GETINFO calls fail.
---
 arm/graph_panel.py |   40 ++++++++++++++++------------------------
 1 file changed, 16 insertions(+), 24 deletions(-)

diff --git a/arm/graph_panel.py b/arm/graph_panel.py
index 1608cc6..e65e623 100644
--- a/arm/graph_panel.py
+++ b/arm/graph_panel.py
@@ -340,33 +340,33 @@ class BandwidthStats(GraphCategory):
       self.title_stats = stats
 
 
-class ConnStats(GraphCategory):
+class ConnectionStats(GraphCategory):
   """
-  Tracks number of connections, counting client and directory connections as
-  outbound. Control connections are excluded from counts.
+  Tracks number of inbound and outbound connections.
   """
 
   TITLE = 'Connection Count'
 
-  def bandwidth_event(self, event):
-    """
-    Fetches connection stats from cached information.
-    """
+  def primary_header(self, width):
+    avg = self.primary.total / max(1, self.primary.tick)
+    return 'Inbound (%s, avg: %s):' % (self.primary.latest_value, avg)
 
+  def secondary_header(self, width):
+    avg = self.secondary.total / max(1, self.secondary.tick)
+    return 'Outbound (%s, avg: %s):' % (self.secondary.latest_value, avg)
+
+  def bandwidth_event(self, event):
     inbound_count, outbound_count = 0, 0
 
     controller = tor_controller()
-
-    or_ports = controller.get_ports(Listener.OR)
-    dir_ports = controller.get_ports(Listener.DIR)
-    control_ports = controller.get_ports(Listener.CONTROL)
+    or_ports = controller.get_ports(Listener.OR, [])
+    dir_ports = controller.get_ports(Listener.DIR, [])
+    control_ports = controller.get_ports(Listener.CONTROL, [])
 
     for entry in arm.util.tracker.get_connection_tracker().get_value():
-      local_port = entry.local_port
-
-      if local_port in or_ports or local_port in dir_ports:
+      if entry.local_port in or_ports or entry.local_port in dir_ports:
         inbound_count += 1
-      elif local_port in control_ports:
+      elif entry.local_port in control_ports:
         pass  # control connection
       else:
         outbound_count += 1
@@ -374,14 +374,6 @@ class ConnStats(GraphCategory):
     self.primary.update(inbound_count)
     self.secondary.update(outbound_count)
 
-  def primary_header(self, width):
-    avg = self.primary.total / max(1, self.primary.tick)
-    return 'Inbound (%s, avg: %s):' % (self.primary.latest_value, avg)
-
-  def secondary_header(self, width):
-    avg = self.secondary.total / max(1, self.secondary.tick)
-    return 'Outbound (%s, avg: %s):' % (self.secondary.latest_value, avg)
-
 
 class ResourceStats(GraphCategory):
   """
@@ -448,7 +440,7 @@ class GraphPanel(panel.Panel):
     }
 
     if CONFIG['features.panels.show.connection']:
-      self.stats[GraphStat.CONNECTIONS] = ConnStats()
+      self.stats[GraphStat.CONNECTIONS] = ConnectionStats()
 
     self.set_pause_attr('stats')
     self.set_pause_attr('_accounting_stats')





More information about the tor-commits mailing list