[tor-commits] [arm/master] Use 'GETINFO bw-event-cache' to prepopulate bandwidth graph information

atagar at torproject.org atagar at torproject.org
Sun Mar 15 03:36:33 UTC 2015


commit 0ab876d82f2a03861f3c4ce4a01a3a59fa38308c
Author: Damian Johnson <atagar at torproject.org>
Date:   Sat Mar 14 20:19:10 2015 -0700

    Use 'GETINFO bw-event-cache' to prepopulate bandwidth graph information
    
    In #14128 added a new controller command that provided up to five minutes of
    bandwidth information. This... is awesome! Not only does it negate any need for
    reading tor's state file (a dirty hack), but it *greatly* improves our user
    experience since we don't need to swap to 15-minute interval graphs!
---
 seth/graph_panel.py |   22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/seth/graph_panel.py b/seth/graph_panel.py
index 1f06890..b89c667 100644
--- a/seth/graph_panel.py
+++ b/seth/graph_panel.py
@@ -190,13 +190,25 @@ class BandwidthStats(GraphCategory):
     GraphCategory.__init__(self, clone)
 
     if not clone:
-      # We both show our 'total' attributes and use it to determine our average.
-      #
-      # If we can get *both* our start time and the totals from tor (via 'GETINFO
-      # traffic/*') then that's ideal, but if not then just track the total for
-      # the time seth is run.
+      # fill in past bandwidth information
 
       controller = tor_controller()
+      bw_entries, is_successful = controller.get_info('bw-event-cache', None), True
+
+      if bw_entries:
+        for entry in bw_entries.split():
+          entry_comp = entry.split(',')
+
+          if len(entry_comp) != 2 or not entry_comp[0].isdigit() or not entry_comp[1].isdigit():
+            log.warn("Tor's 'GETINFO bw-event-cache' provided malformed output: %s" % bw_entries)
+            is_successful = False
+            break
+
+          self.primary.update(int(entry_comp[0]))
+          self.secondary.update(int(entry_comp[1]))
+
+        if is_successful:
+          log.info('Bandwidth graph has information for the last %s' % str_tools.time_label(len(bw_entries.split()), is_long = True))
 
       read_total = controller.get_info('traffic/read', None)
       write_total = controller.get_info('traffic/written', None)





More information about the tor-commits mailing list