[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [arm/master] Moving graph stat constants to config
commit 307829656986d48ceb9c5d9da5bd4c16a1ab6ca2
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Sun Oct 26 14:17:59 2014 -0700
Moving graph stat constants to config
Moving the string constants to the config. That's what it's there for.
---
arm/config/attributes.cfg | 13 +++++++++++++
arm/graph_panel.py | 44 +++++++++++++++-----------------------------
2 files changed, 28 insertions(+), 29 deletions(-)
diff --git a/arm/config/attributes.cfg b/arm/config/attributes.cfg
index 5b49a37..7452a71 100644
--- a/arm/config/attributes.cfg
+++ b/arm/config/attributes.cfg
@@ -35,3 +35,16 @@ attr.graph.intervals 15 minute => 900
attr.graph.intervals 30 minute => 1800
attr.graph.intervals hourly => 3600
attr.graph.intervals daily => 86400
+
+attr.graph.title bandwidth => Bandwidth
+attr.graph.title connections => Connection Count
+attr.graph.title resources => System Resources
+
+attr.graph.header.primary bandwidth => Download
+attr.graph.header.primary connections => Inbound
+attr.graph.header.primary resources => CPU
+
+attr.graph.header.secondary bandwidth => Upload
+attr.graph.header.secondary connections => Outbound
+attr.graph.header.secondary resources => Memory
+
diff --git a/arm/graph_panel.py b/arm/graph_panel.py
index a15a212..f0a1ee7 100644
--- a/arm/graph_panel.py
+++ b/arm/graph_panel.py
@@ -31,7 +31,7 @@ from arm.util import bandwidth_from_state, msg, panel, tor_controller
from stem.control import Listener
from stem.util import conf, enum, log, str_tools, system
-GraphStat = enum.Enum('BANDWIDTH', 'CONNECTIONS', 'SYSTEM_RESOURCES')
+GraphStat = enum.Enum(('BANDWIDTH', 'bandwidth'), ('CONNECTIONS', 'connections'), ('SYSTEM_RESOURCES', 'resources'))
# maps 'features.graph.type' config values to the initial types
@@ -67,6 +67,9 @@ def conf_handler(key, value):
CONFIG = conf.config_dict('arm', {
'attr.hibernate_color': {},
'attr.graph.intervals': {},
+ 'attr.graph.title': {},
+ 'attr.graph.header.primary': {},
+ 'attr.graph.header.secondary': {},
'features.graph.height': 7,
'features.graph.interval': 'each second',
'features.graph.bound': 1,
@@ -142,10 +145,6 @@ class GraphCategory(object):
:var list secondary_header_stats: additional information for the secondary header
"""
- TITLE = ''
- PRIMARY_HEADER = ''
- SECONDARY_HEADER = ''
-
def __init__(self, clone = None):
if clone:
self.primary = Stat(clone.primary)
@@ -176,10 +175,6 @@ class BandwidthStats(GraphCategory):
Uses tor BW events to generate bandwidth usage graph.
"""
- TITLE = 'Bandwidth'
- PRIMARY_HEADER = 'Download'
- SECONDARY_HEADER = 'Upload'
-
def __init__(self, clone = None):
GraphCategory.__init__(self, clone)
@@ -309,10 +304,6 @@ class ConnectionStats(GraphCategory):
Tracks number of inbound and outbound connections.
"""
- TITLE = 'Connection Count'
- PRIMARY_HEADER = 'Inbound'
- SECONDARY_HEADER = 'Outbound'
-
def bandwidth_event(self, event):
inbound_count, outbound_count = 0, 0
@@ -344,10 +335,6 @@ class ResourceStats(GraphCategory):
Tracks cpu and memory usage of the tor process.
"""
- TITLE = 'System Resources'
- PRIMARY_HEADER = 'CPU'
- SECONDARY_HEADER = 'Memory'
-
def bandwidth_event(self, event):
resources = arm.util.tracker.get_resource_tracker().get_value()
self.primary.update(resources.cpu_sample * 100) # decimal percentage to whole numbers
@@ -602,23 +589,22 @@ class GraphPanel(panel.Panel):
graph_column = min((width - 10) / 2, CONFIG['features.graph.max_width'])
if self.is_title_visible():
- title_stats = str_tools.join(param.title_stats, ', ', width - len(param.TITLE) - 4)
- title = '%s (%s):' % (param.TITLE, title_stats) if title_stats else '%s:' % param.TITLE
+ title = CONFIG['attr.graph.title'].get(self.current_display, '')
+ title_stats = str_tools.join(param.title_stats, ', ', width - len(title) - 4)
+ title = '%s (%s):' % (title, title_stats) if title_stats else '%s:' % title
self.addstr(0, 0, title, curses.A_STANDOUT)
# top labels
- primary_header_stats = str_tools.join(param.primary_header_stats, '', (width / 2) - len(param.PRIMARY_HEADER) - 4)
- left = '%s (%s):' % (param.PRIMARY_HEADER, primary_header_stats) if primary_header_stats else '%s:' % param.PRIMARY_HEADER
-
- secondary_header_stats = str_tools.join(param.secondary_header_stats, '', (width / 2) - len(param.SECONDARY_HEADER) - 4)
- right = '%s (%s):' % (param.SECONDARY_HEADER, secondary_header_stats) if secondary_header_stats else '%s:' % param.SECONDARY_HEADER
-
- if left:
- self.addstr(1, 0, left, curses.A_BOLD, PRIMARY_COLOR)
+ primary_header = CONFIG['attr.graph.header.primary'].get(self.current_display, '')
+ primary_header_stats = str_tools.join(param.primary_header_stats, '', (width / 2) - len(primary_header) - 4)
+ left = '%s (%s):' % (primary_header, primary_header_stats) if primary_header_stats else '%s:' % primary_header
+ self.addstr(1, 0, left, curses.A_BOLD, PRIMARY_COLOR)
- if right:
- self.addstr(1, graph_column + 5, right, curses.A_BOLD, SECONDARY_COLOR)
+ secondary_header = CONFIG['attr.graph.header.secondary'].get(self.current_display, '')
+ secondary_header_stats = str_tools.join(param.secondary_header_stats, '', (width / 2) - len(secondary_header) - 4)
+ right = '%s (%s):' % (secondary_header, secondary_header_stats) if secondary_header_stats else '%s:' % secondary_header
+ self.addstr(1, graph_column + 5, right, curses.A_BOLD, SECONDARY_COLOR)
# determines max/min value on the graph
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits