summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Levy <alevy@redhat.com>2011-08-14 12:15:23 -0700
committerAlon Levy <alevy@redhat.com>2011-08-14 12:15:23 -0700
commit9715ba55567f5d99d32ab51e6af967de149592c9 (patch)
tree80456bc910cc760b2f5ee6422b29f039e5e7118c
parentaf4fcc0d577d85828b10057aaac5270b01be1a3d (diff)
rate_to_string + --debug
-rwxr-xr-xbandwidthmon19
1 files changed, 16 insertions, 3 deletions
diff --git a/bandwidthmon b/bandwidthmon
index 63c37d2..ae9afc5 100755
--- a/bandwidthmon
+++ b/bandwidthmon
@@ -7,8 +7,9 @@ import gtk
import time
import socket
-debug = True
+debug = False
def dprint(x):
+ global debug
if not debug:
return
print x
@@ -63,6 +64,15 @@ class Bandwidth(object):
return 0
return float(self.total) / (self.last_time - self.start_time)
+def rate_to_string(rate):
+ if rate == 0:
+ return '0'
+ if rate < 1024:
+ return "< 1k"
+ if rate < 1024 * 1024:
+ return '%3.2f KiB' % (float(rate) / 1024)
+ return '%3.2f MiB' % (float(rate) / 1024 / 1024)
+
class UI(object):
def __init__(self, pairs):
"""
@@ -117,8 +127,8 @@ class UI(object):
def on_bw_average(self, bw):
labels = self.bw_to_ui[bw]
- labels['label_avg'].set_label(str(bw.average()))
- labels['label_avg_from_reset'].set_label(str(bw.global_average()))
+ labels['label_avg'].set_label(rate_to_string(bw.average()))
+ labels['label_avg_from_reset'].set_label(rate_to_string(bw.global_average()))
def add_packet(self, src, dst, data):
if src in self.port_in_bw:
@@ -189,10 +199,13 @@ def main():
# only allow same host for all ports - easier to implement.
p.add_argument('--remote-host', default='127.0.0.1')
p.add_argument('--listen-host', default='127.0.0.1')
+ p.add_argument('--debug')
args = p.parse_args(sys.argv[1:])
if len(args.listen_port) != len(args.remote_port):
print "must supply same amount of listening and remote ports"
sys.exit(1)
+ global debug
+ debug = not not args.debug
ui = UI(zip(args.listen_port, args.remote_port))
for listen_port, remote_port in zip(args.listen_port, args.remote_port):
setup_proxy(ui=ui, listen_port=listen_port, listen_host=args.listen_host,