[tor-commits] [arm/master] Moving bandwidth population strings to config
atagar at torproject.org
atagar at torproject.org
Tue Sep 9 02:33:47 UTC 2014
commit e6e70bb4c3229ef9a1cbe038cf3607c0641ab83b
Author: Damian Johnson <atagar at torproject.org>
Date: Mon Sep 8 13:26:48 2014 -0700
Moving bandwidth population strings to config
Moving the strings out of the code, and making a new 'msg.panle.*' grouping for
the panel content.
---
arm/config/strings.cfg | 8 ++++++--
arm/graphing/bandwidth_stats.py | 24 +++++++++---------------
arm/header_panel.py | 6 +++---
3 files changed, 18 insertions(+), 20 deletions(-)
diff --git a/arm/config/strings.cfg b/arm/config/strings.cfg
index f44e168..465e208 100644
--- a/arm/config/strings.cfg
+++ b/arm/config/strings.cfg
@@ -5,6 +5,7 @@
# * config parsing or handling configuration options
# * debug concerns the --debug argument
# * misc anything that doesn't fit into a present namespace
+# * panel used after startup by our curses panels
# * setup notificaitons or issues arising while starting arm
# * tracker related to tracking resource usage or connections
# * usage usage information about starting and running arm
@@ -19,8 +20,11 @@ msg.config.nothing_loaded No armrc loaded, using defaults. You can customize arm
msg.debug.saving_to_path Saving a debug log to {path}, please check it for sensitive information before sharing it.
msg.debug.unable_to_write_file Unable to write to our debug log file ({path}): {error}
-msg.misc.fd_used_at_sixty_percent Tor's file descriptor usage is at {percentage}%.
-msg.misc.fd_used_at_ninety_percent Tor's file descriptor usage is at {percentage}%. If you run out Tor will be unable to continue functioning.
+msg.panel.graphing.prepopulation_all_successful Read the last day of bandwidth history from the state file
+msg.panel.graphing.prepopulation_successful Read the last day of bandwidth history from the state file ({duration} is missing)
+msg.panel.graphing.prepopulation_failure Unable to prepopulate bandwidth information ({error})
+msg.panel.header.fd_used_at_sixty_percent Tor's file descriptor usage is at {percentage}%.
+msg.panel.header.fd_used_at_ninety_percent Tor's file descriptor usage is at {percentage}%. If you run out Tor will be unable to continue functioning.
msg.setup.arm_is_running_as_root Arm is currently running with root permissions. This isn't a good idea, nor should it be necessary. Try starting arm with "sudo -u {tor_user} arm" instead.
msg.setup.chroot_doesnt_exist The chroot path set in your config ({path}) doesn't exist.
diff --git a/arm/graphing/bandwidth_stats.py b/arm/graphing/bandwidth_stats.py
index 2a21a0a..20898af 100644
--- a/arm/graphing/bandwidth_stats.py
+++ b/arm/graphing/bandwidth_stats.py
@@ -14,6 +14,8 @@ from arm.util import tor_controller
from stem.control import State
from stem.util import conf, log, str_tools, system
+from arm.util import msg
+
def conf_handler(key, value):
if key == 'features.graph.bw.accounting.rate':
@@ -39,9 +41,6 @@ COLLAPSE_WIDTH = 135
ACCOUNTING_ARGS = ('status', 'reset_time', 'read', 'written', 'read_limit', 'writtenLimit')
-PREPOPULATE_SUCCESS_MSG = 'Read the last day of bandwidth history from the state file'
-PREPOPULATE_FAILURE_MSG = 'Unable to prepopulate bandwidth information (%s)'
-
class BandwidthStats(graph_panel.GraphStats):
"""
@@ -168,8 +167,7 @@ class BandwidthStats(graph_panel.GraphStats):
# results associated with this tor instance
if not uptime or '-' not in uptime:
- msg = PREPOPULATE_FAILURE_MSG % 'insufficient uptime'
- log.notice(msg)
+ log.notice(msg('panel.graphing.prepopulation_failure', error = 'insufficient uptime'))
return False
# get the user's data directory (usually '~/.tor')
@@ -177,8 +175,7 @@ class BandwidthStats(graph_panel.GraphStats):
data_dir = controller.get_conf('DataDirectory', None)
if not data_dir:
- msg = PREPOPULATE_FAILURE_MSG % 'data directory not found'
- log.notice(msg)
+ log.notice(msg('panel.graphing.prepopulation_failure', error = 'data directory not found'))
return False
# attempt to open the state file
@@ -186,8 +183,7 @@ class BandwidthStats(graph_panel.GraphStats):
try:
state_file = open('%s%s/state' % (CONFIG['tor.chroot'], data_dir), 'r')
except IOError:
- msg = PREPOPULATE_FAILURE_MSG % 'unable to read the state file'
- log.notice(msg)
+ log.notice(msg('panel.graphing.prepopulation_failure', error = 'unable to read the state file'))
return False
# get the BWHistory entries (ordered oldest to newest) and number of
@@ -227,8 +223,7 @@ class BandwidthStats(graph_panel.GraphStats):
missing_write_entries = int((time.time() - last_write_time) / 900)
if not bw_read_entries or not bw_write_entries or not last_read_time or not last_write_time:
- msg = PREPOPULATE_FAILURE_MSG % 'bandwidth stats missing from state file'
- log.notice(msg)
+ log.notice(msg('panel.graphing.prepopulation_failure', error = 'bandwidth stats missing from state file'))
return False
# fills missing entries with the last value
@@ -272,13 +267,12 @@ class BandwidthStats(graph_panel.GraphStats):
del self.primary_counts[interval_index][self.max_column + 1:]
del self.secondary_counts[interval_index][self.max_column + 1:]
- msg = PREPOPULATE_SUCCESS_MSG
missing_sec = time.time() - min(last_read_time, last_write_time)
if missing_sec:
- msg += ' (%s is missing)' % str_tools.time_label(missing_sec, 0, True)
-
- log.notice(msg)
+ log.notice(msg('panel.graphing.prepopulation_successful', duration = str_tools.time_label(missing_sec, 0, True)))
+ else:
+ log.notice(msg('panel.graphing.prepopulation_all_successful'))
return True
diff --git a/arm/header_panel.py b/arm/header_panel.py
index 49ec6dc..e0ba247 100644
--- a/arm/header_panel.py
+++ b/arm/header_panel.py
@@ -17,7 +17,7 @@ import stem
from stem.control import Listener
from stem.util import conf, log, proc, str_tools, system
-from util import msg, tor_controller, panel, tracker
+from arm.util import msg, tor_controller, panel, tracker
MIN_DUAL_COL_WIDTH = 141 # minimum width where we'll show two columns
SHOW_FD_THRESHOLD = 60 # show file descriptor usage if usage is over this percentage
@@ -449,11 +449,11 @@ class Sampling(object):
fd_percent = 100 * self.fd_used / self.fd_limit
if fd_percent >= 90:
- log_msg = msg('misc.fd_used_at_ninety_percent', percentage = fd_percent)
+ log_msg = msg('panel.header.fd_used_at_ninety_percent', percentage = fd_percent)
log.log_once('fd_used_at_ninety_percent', log.WARN, log_msg)
log.DEDUPLICATION_MESSAGE_IDS.add('fd_used_at_sixty_percent')
elif fd_percent >= 60:
- log_msg = msg('misc.fd_used_at_sixty_percent', percentage = fd_percent)
+ log_msg = msg('panel.header.fd_used_at_sixty_percent', percentage = fd_percent)
log.log_once('fd_used_at_sixty_percent', log.NOTICE, log_msg)
def format(self, message, crop_width = None):
More information about the tor-commits
mailing list