commit 3907aa3dcda05b073248e787592b62e68bef1b97 Author: Damian Johnson atagar@torproject.org Date: Sun Oct 12 16:42:58 2014 -0700
Moving UPDATE_INTERVALS to configuration
Simply moving a constant from the graph panel to the config. --- arm/config/attributes.cfg | 9 ++++++++ arm/graphing/bandwidth_stats.py | 5 +++-- arm/graphing/graph_panel.py | 45 ++++++++++++++------------------------- arm/menu/actions.py | 11 ++++++---- 4 files changed, 35 insertions(+), 35 deletions(-)
diff --git a/arm/config/attributes.cfg b/arm/config/attributes.cfg index 6f1fea5..5b49a37 100644 --- a/arm/config/attributes.cfg +++ b/arm/config/attributes.cfg @@ -26,3 +26,12 @@ attr.version_status_colors unknown => cyan attr.hibernate_color awake => green attr.hibernate_color soft => yellow attr.hibernate_color hard => red + +attr.graph.intervals each second => 1 +attr.graph.intervals 5 seconds => 5 +attr.graph.intervals 30 seconds => 30 +attr.graph.intervals minutely => 60 +attr.graph.intervals 15 minute => 900 +attr.graph.intervals 30 minute => 1800 +attr.graph.intervals hourly => 3600 +attr.graph.intervals daily => 86400 diff --git a/arm/graphing/bandwidth_stats.py b/arm/graphing/bandwidth_stats.py index f91ce98..4d52aae 100644 --- a/arm/graphing/bandwidth_stats.py +++ b/arm/graphing/bandwidth_stats.py @@ -18,6 +18,7 @@ ACCOUNTING_RATE = 5
CONFIG = conf.config_dict('arm', { 'attr.hibernate_color': {}, + 'attr.graph.intervals': {}, 'features.graph.bw.transferInBytes': False, 'features.graph.bw.accounting.show': True, 'tor.chroot': '', @@ -124,8 +125,8 @@ class BandwidthStats(graph_panel.GraphStats):
interval_index = 0
- for index_entry in graph_panel.UPDATE_INTERVALS: - if index_entry[1] == 900: + for interval_rate in CONFIG['attr.graph.intervals'].values(): + if int(interval_rate) == 900: break else: interval_index += 1 diff --git a/arm/graphing/graph_panel.py b/arm/graphing/graph_panel.py index 99c1d3b..77f9404 100644 --- a/arm/graphing/graph_panel.py +++ b/arm/graphing/graph_panel.py @@ -28,20 +28,7 @@ from arm.util import msg, panel, tor_controller
from stem.util import conf, enum, log, str_tools
-# time intervals at which graphs can be updated - -UPDATE_INTERVALS = [ - ('each second', 1), - ('5 seconds', 5), - ('30 seconds', 30), - ('minutely', 60), - ('15 minute', 900), - ('30 minute', 1800), - ('hourly', 3600), - ('daily', 86400), -] - -GraphStat = enum.Enum("BANDWIDTH", "CONNECTIONS", "SYSTEM_RESOURCES") +GraphStat = enum.Enum('BANDWIDTH', 'CONNECTIONS', 'SYSTEM_RESOURCES')
# maps 'features.graph.type' config values to the initial types
@@ -66,8 +53,6 @@ def conf_handler(key, value): return max(MIN_GRAPH_HEIGHT, value) elif key == 'features.graph.max_width': return max(1, value) - elif key == 'features.graph.interval': - return max(0, min(len(UPDATE_INTERVALS) - 1, value)) elif key == 'features.graph.bound': return max(0, min(2, value))
@@ -75,6 +60,7 @@ def conf_handler(key, value): # used for setting defaults when initializing GraphStats and GraphPanel instances
CONFIG = conf.config_dict('arm', { + 'attr.graph.intervals': {}, 'features.graph.height': 7, 'features.graph.interval': 0, 'features.graph.bound': 1, @@ -90,7 +76,7 @@ class GraphStats: """ Module that's expected to update dynamically and provide attributes to be graphed. Up to two graphs (a 'primary' and 'secondary') can be displayed at a - time and timescale parameters use the labels defined in UPDATE_INTERVALS. + time and timescale parameters use the labels defined in CONFIG['attr.graph.intervals']. """
def __init__(self): @@ -116,7 +102,7 @@ class GraphStats: self.max_primary, self.max_secondary = {}, {} self.primary_counts, self.secondary_counts = {}, {}
- for i in range(len(UPDATE_INTERVALS)): + for i in range(len(CONFIG['attr.graph.intervals'])): # recent rates for graph
self.max_primary[i] = 0 @@ -171,7 +157,7 @@ class GraphStats:
if self._graph_panel and self.is_selected and not self._graph_panel.is_paused(): # use the minimum of the current refresh rate and the panel's - update_rate = UPDATE_INTERVALS[self._graph_panel.update_interval][1] + update_rate = int(CONFIG['attr.graph.intervals'].values()[self._graph_panel.update_interval]) return (self.tick + 1) % update_rate == 0 else: return False @@ -222,8 +208,9 @@ class GraphStats:
self.tick += 1
- for i in range(len(UPDATE_INTERVALS)): - lable, timescale = UPDATE_INTERVALS[i] + for i in range(len(CONFIG['attr.graph.intervals'])): + lable, timescale = CONFIG['attr.graph.intervals'].items()[i] + timescale = int(timescale)
self.primary_counts[i][0] += primary self.secondary_counts[i][0] += secondary @@ -252,6 +239,10 @@ class GraphPanel(panel.Panel): def __init__(self, stdscr): panel.Panel.__init__(self, stdscr, 'graph', 0) self.update_interval = CONFIG['features.graph.interval'] + + if self.update_interval < 0 or self.update_interval > len(CONFIG['attr.graph.intervals']) - 1: + self.update_interval = 0 # user configured it with a value that's out of bounds + 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 @@ -286,7 +277,7 @@ class GraphPanel(panel.Panel): else: log.notice(msg('panel.graphing.prepopulation_all_successful'))
- self.update_interval = 4 + self.update_interval = 4 except ValueError as exc: log.info(msg('panel.graphing.prepopulation_failure', error = str(exc)))
@@ -419,7 +410,7 @@ class GraphPanel(panel.Panel): elif key.match('i'): # provides menu to pick graph panel update interval
- options = [label for (label, _) in UPDATE_INTERVALS] + options = CONFIG['attr.graph.intervals'].keys() selection = arm.popups.show_menu('Update Interval:', options, self.update_interval)
if selection != -1: @@ -434,7 +425,7 @@ class GraphPanel(panel.Panel): ('r', 'resize graph', None), ('s', 'graphed stats', self.current_display if self.current_display else 'none'), ('b', 'graph bounds', self.bounds.lower()), - ('i', 'graph update interval', UPDATE_INTERVALS[self.update_interval][0]), + ('i', 'graph update interval', CONFIG['attr.graph.intervals'].keys()[self.update_interval]), ]
def draw(self, width, height): @@ -534,11 +525,7 @@ class GraphPanel(panel.Panel):
# bottom labeling of x-axis
- interval_sec = 1 # seconds per labeling - - for i in range(len(UPDATE_INTERVALS)): - if i == self.update_interval: - interval_sec = UPDATE_INTERVALS[i][1] + interval_sec = int(CONFIG['attr.graph.intervals'].values()[self.update_interval]) # seconds per labeling
interval_spacing = 10 if graph_column >= WIDE_LABELING_GRAPH_COL else 5 units_label, decimal_precision = None, 0 diff --git a/arm/menu/actions.py b/arm/menu/actions.py index 3aa941d..b95f1fc 100644 --- a/arm/menu/actions.py +++ b/arm/menu/actions.py @@ -17,8 +17,9 @@ import stem.util.connection
from stem.util import conf, str_tools
-CONFIG = conf.config_dict("arm", { - "features.log.showDuplicateEntries": False, +CONFIG = conf.config_dict('arm', { + 'features.log.showDuplicateEntries': False, + 'attr.graph.intervals': {}, })
@@ -167,8 +168,10 @@ def make_graph_menu(graph_panel): interval_menu = arm.menu.item.Submenu("Interval") interval_group = arm.menu.item.SelectionGroup(graph_panel.set_update_interval, graph_panel.get_update_interval())
- for i in range(len(arm.graphing.graph_panel.UPDATE_INTERVALS)): - label = arm.graphing.graph_panel.UPDATE_INTERVALS[i][0] + graph_intervals = CONFIG['attr.graph.intervals'] + + for i in range(len(graph_intervals)): + label = graph_intervals.keys()[i] label = str_tools._to_camel_case(label, divider = " ") interval_menu.add(arm.menu.item.SelectionMenuItem(label, interval_group, i))
tor-commits@lists.torproject.org