[tor-commits] [arm/master] Moving graph stat inititalization into the graph panel

atagar at torproject.org atagar at torproject.org
Sun Oct 19 01:28:43 UTC 2014


commit 6ea5b4a6acd94bb8151ad67d92820d69c0341fe2
Author: Damian Johnson <atagar at torproject.org>
Date:   Sun Oct 12 15:20:41 2014 -0700

    Moving graph stat inititalization into the graph panel
    
    Hmmmm, not sure why we did this. Our controller initialized graph stats then
    added them to the graph panel. Maybe this made sense with a past feature or
    pausing implementation.
    
    ... or maybe it still makes sense and I'm not spotting why. It's a lot simpler
    for the panel to be responsible for its own stats so going with this for now.
    Guess we'll see if this bites me down the line.
---
 arm/controller.py           |   45 -----------------------------------
 arm/graphing/graph_panel.py |   55 ++++++++++++++++++++++++++++++++++---------
 2 files changed, 44 insertions(+), 56 deletions(-)

diff --git a/arm/controller.py b/arm/controller.py
index 48034e9..42d0531 100644
--- a/arm/controller.py
+++ b/arm/controller.py
@@ -52,17 +52,9 @@ CONFIG = conf.config_dict("arm", {
   "features.redrawRate": 5,
   "features.refreshRate": 5,
   "features.confirmQuit": True,
-  "features.graph.type": 1,
-  "features.graph.bw.prepopulate": True,
   "start_time": 0,
 }, conf_handler)
 
-GraphStat = enum.Enum("BANDWIDTH", "CONNECTIONS", "SYSTEM_RESOURCES")
-
-# maps 'features.graph.type' config values to the initial types
-
-GRAPH_INIT_STATS = {1: GraphStat.BANDWIDTH, 2: GraphStat.CONNECTIONS, 3: GraphStat.SYSTEM_RESOURCES}
-
 
 def get_controller():
   """
@@ -173,43 +165,6 @@ def init_controller(stdscr, start_time):
 
   ARM_CONTROLLER = Controller(stdscr, sticky_panels, page_panels)
 
-  # additional configuration for the graph panel
-
-  graph_panel = ARM_CONTROLLER.get_panel("graph")
-
-  if graph_panel:
-    # statistical monitors for graph
-
-    bw_stats = arm.graphing.bandwidth_stats.BandwidthStats()
-    graph_panel.add_stats(GraphStat.BANDWIDTH, bw_stats)
-    graph_panel.add_stats(GraphStat.SYSTEM_RESOURCES, arm.graphing.resource_stats.ResourceStats())
-
-    if CONFIG["features.panels.show.connection"]:
-      graph_panel.add_stats(GraphStat.CONNECTIONS, arm.graphing.conn_stats.ConnStats())
-
-    # sets graph based on config parameter
-
-    try:
-      initial_stats = GRAPH_INIT_STATS.get(CONFIG["features.graph.type"])
-      graph_panel.set_stats(initial_stats)
-    except ValueError:
-      pass  # invalid stats, maybe connections when lookups are disabled
-
-    # prepopulates bandwidth values from state file
-
-    if CONFIG["features.graph.bw.prepopulate"] and tor_controller().is_alive():
-      try:
-        missing_seconds = bw_stats.prepopulate_from_state()
-
-        if missing_seconds:
-          log.notice(msg('panel.graphing.prepopulation_successful', duration = str_tools.time_label(missing_seconds, 0, True)))
-        else:
-          log.notice(msg('panel.graphing.prepopulation_all_successful'))
-
-        graph_panel.update_interval = 4
-      except ValueError as exc:
-        log.info(msg('panel.graphing.prepopulation_failure', error = str(exc)))
-
 
 class LabelPanel(panel.Panel):
   """
diff --git a/arm/graphing/graph_panel.py b/arm/graphing/graph_panel.py
index a034e56..4450c6c 100644
--- a/arm/graphing/graph_panel.py
+++ b/arm/graphing/graph_panel.py
@@ -24,9 +24,9 @@ import arm.controller
 
 import stem.control
 
-from arm.util import panel, tor_controller
+from arm.util import msg, panel, tor_controller
 
-from stem.util import conf, enum, str_tools
+from stem.util import conf, enum, log, str_tools
 
 # time intervals at which graphs can be updated
 
@@ -41,6 +41,12 @@ UPDATE_INTERVALS = [
   ('daily', 86400),
 ]
 
+GraphStat = enum.Enum("BANDWIDTH", "CONNECTIONS", "SYSTEM_RESOURCES")
+
+# maps 'features.graph.type' config values to the initial types
+
+GRAPH_INIT_STATS = {1: GraphStat.BANDWIDTH, 2: GraphStat.CONNECTIONS, 3: GraphStat.SYSTEM_RESOURCES}
+
 DEFAULT_CONTENT_HEIGHT = 4  # space needed for labeling above and below the graph
 PRIMARY_COLOR, SECONDARY_COLOR = 'green', 'cyan'
 MIN_GRAPH_HEIGHT = 1
@@ -74,6 +80,9 @@ CONFIG = conf.config_dict('arm', {
   'features.graph.bound': 1,
   'features.graph.max_width': 150,
   'features.graph.showIntermediateBounds': True,
+  'features.graph.type': 1,
+  'features.panels.show.connection': True,
+  'features.graph.bw.prepopulate': True,
 }, conf_handler)
 
 
@@ -246,9 +255,41 @@ class GraphPanel(panel.Panel):
     self.bounds = list(Bounds)[CONFIG['features.graph.bound']]
     self.graph_height = CONFIG['features.graph.height']
     self.current_display = None    # label of the stats currently being displayed
-    self.stats = {}                # available stats (mappings of label -> instance)
+
+    self.stats = {
+      GraphStat.BANDWIDTH: arm.graphing.bandwidth_stats.BandwidthStats(),
+      GraphStat.SYSTEM_RESOURCES: arm.graphing.resource_stats.ResourceStats(),
+    }
+
+    if CONFIG['features.panels.show.connection']:
+      self.stats[GraphStat.CONNECTIONS] = arm.graphing.conn_stats.ConnStats()
+
+    for stat in self.stats.values():
+      stat._graph_panel = self
+
     self.set_pause_attr('stats')
 
+    try:
+      initial_stats = GRAPH_INIT_STATS.get(CONFIG['features.graph.type'])
+      self.set_stats(initial_stats)
+    except ValueError:
+      pass  # invalid stats, maybe connections when lookups are disabled
+
+    # prepopulates bandwidth values from state file
+
+    if CONFIG["features.graph.bw.prepopulate"] and tor_controller().is_alive():
+      try:
+        missing_seconds = self.stats[GraphStat.BANDWIDTH].prepopulate_from_state()
+
+        if missing_seconds:
+          log.notice(msg('panel.graphing.prepopulation_successful', duration = str_tools.time_label(missing_seconds, 0, True)))
+        else:
+          log.notice(msg('panel.graphing.prepopulation_all_successful'))
+
+        self.update_interval = 4 
+      except ValueError as exc:
+        log.info(msg('panel.graphing.prepopulation_failure', error = str(exc)))
+
   def get_update_interval(self):
     """
     Provides the rate that we update the graph at.
@@ -521,14 +562,6 @@ class GraphPanel(panel.Panel):
 
       param.draw(self, width, height)  # allows current stats to modify the display
 
-  def add_stats(self, label, stats):
-    """
-    Makes GraphStats instance available in the panel.
-    """
-
-    stats._graph_panel = self
-    self.stats[label] = stats
-
   def get_stats(self):
     """
     Provides the currently selected stats label.





More information about the tor-commits mailing list