lzkill lzkill - 2 years ago 82
Python Question

How read the bandwidth limit parameter from Tor with Stem

How could one read the Tor parameter for bandwidth limit using Stem? I've looked around theAPI and could'n find a method or GETINFO parameter to such a task.

Answer Source

assuming you mean the maximum bandwidth you've configured your relay for it's...

from stem.control import Controller

from stem.util.str_tools import get_size_label

with Controller.from_port() as controller:

  bw_rate = get_size_label(int(controller.get_conf('BandwidthRate', '0')))
  bw_burst = get_size_label(int(controller.get_conf('BandwidthBurst', '0')))
  print "you're configured to relay at most %s/s, with bursts up to %s/s" % (bw_rate, bw_burst)

... for example...

% python scrap.py 
you're configured to relay at most 1 GB/s, with bursts up to 1 GB/s

The git repository also has a new get_effective_rate() method which takes additional configuration attributes into account.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download