TorCtl.StatsSupport
index
/crypto/home/potentiate/output/code/tor/SVN/torctl/python/TorCtl/StatsSupport.py

Support classes for statisics gathering
 
The StatsSupport package contains several classes that extend PathSupport to
gather continuous statistics on the Tor network.
 
The main entrypoint is to extend or create an instance of the StatsHandler
class. The StatsHandler extends from TorCtl.PathSupport.PathBuilder, which is
itself a TorCtl.EventHandler. The StatsHandler listens to CIRC and STREAM
events and gathers all manner of statics on their creation and failure before
passing the events back up to the PathBuilder code, which manages the actual
construction and the attachment of streams to circuits.
 
The package also contains a number of support classes that help gather
additional statistics on the reliability and performance of routers.
 
For the purpose of accounting failures, the code tracks two main classes of
failure: 'actual' failure and 'suspected' failure. The general rule is that an
actual failure is attributed to the node that directly handled the circuit or
stream. For streams, this is considered to be the exit node. For circuits, it
is both the extender and the extendee. 'Suspected' failures, on the other
hand, are attributed to every member of the circuit up until the extendee for
circuits, and all hops for streams.
 
For bandwidth accounting, the average stream bandwidth and the average ratio
of stream bandwidth to advertised bandwidth are tracked, and when the
statistics are written, a Z-test is performed to calculate the probabilities
of these values assuming a normal distribution. Note, however, that it has not
been verified that this distribution is actually normal. It is likely to be
something else (pareto, perhaps?).

 
Modules
       
TorCtl.PathSupport
TorCtl.TorCtl
TorCtl.TorUtil
copy
math
random
re
sys
time

 
Classes
       
TorCtl.PathSupport.PathBuilder(TorCtl.TorCtl.EventHandler)
StatsHandler
BandwidthStats
ReasonRouterList
FailedRouterList
SuspectRouterList
TorCtl.TorCtl.Router
StatsRouter

 
class BandwidthStats
    Class that manages observed bandwidth through a Router
 
  Methods defined here:
__init__(self)
add_bw(self, bytes, duration)
Add an observed transfer of 'bytes' for 'duration' seconds

 
class FailedRouterList(ReasonRouterList)
    Helper class to track all routers that failed for a given
reason. The main difference between this and the normal
ReasonRouterList is the sort order and the verification.
 
  Methods defined here:
__init__(self, reason)
sort_list(self)

Methods inherited from ReasonRouterList:
add_r(self, r)
Add a router to the list for this reason
total_failed(self)
Get a list of total failures for this reason
total_suspected(self)
Get a list of total suspected failures for this reason
write_list(self, f)
Write the list of failure counts for this reason 'f'

 
class ReasonRouterList
    Helper class to track which Routers have failed for a given reason
 
  Methods defined here:
__init__(self, reason)
add_r(self, r)
Add a router to the list for this reason
sort_list(self)
total_failed(self)
Get a list of total failures for this reason
total_suspected(self)
Get a list of total suspected failures for this reason
write_list(self, f)
Write the list of failure counts for this reason 'f'

 
class StatsHandler(TorCtl.PathSupport.PathBuilder)
    An extension of PathSupport.PathBuilder that keeps track of 
router statistics for every circuit and stream
 
 
Method resolution order:
StatsHandler
TorCtl.PathSupport.PathBuilder
TorCtl.TorCtl.EventHandler

Methods defined here:
__init__(self, c, slmgr)
circ_status_event(self, c)
count_stream_reason_failed(self, s, reason)
Count the routers involved in a failure
count_stream_suspects(self, s, lreason, reason)
Count the routers 'suspected' of being involved in a failure
ns_event(self, n)
reset_stats(self)
run_zbtest(self)
Run unweighted z-test to calculate the probabilities of a node
having a given stream bandwidth based on the Normal distribution
run_zrtest(self)
Run unweighted z-test to calculate the probabilities of a node
having a given ratio of stream bandwidth to advertised bandwidth
based on the Normal distribution
stream_status_event(self, s)
write_reasons(self, f, reasons, name)
Write out all the failure reasons and statistics for all Routers
write_routers(self, f, rlist, name)
Write out all the usage statistics for all Routers
write_stats(self, filename)
Write out all the statistics the StatsHandler has gathered

Methods inherited from TorCtl.PathSupport.PathBuilder:
attach_stream_any(self, stream, badcircs)
Attach a stream to a valid circuit, avoiding any in 'badcircs'
bandwidth_event(self, b)
build_path(self)
Get a path from the SelectionManager's PathSelector, can be used 
e.g. for generating paths without actually creating any circuits
heartbeat_event(self, event)
This function handles dispatching scheduled jobs. If you 
extend PathBuilder and want to implement this function for 
some reason, be sure to call the parent class
new_desc_event(self, d)
read_routers(self, nslist)
schedule_immediate(self, job)
Schedules an immediate job to be run before the next event is
processed.
schedule_low_prio(self, job)
Schedules a job to be run when a non-time critical event arrives.
schedule_selmgr(self, job)
Schedules an immediate job to be run before the next event is
processed. Also notifies the selection manager that it needs
to update itself.
stream_bw_event(self, s)

Methods inherited from TorCtl.TorCtl.EventHandler:
address_mapped_event(self, event)
Called when Tor adds a mapping for an address if listening
to ADDRESSMAPPED events.
msg_event(self, event)
Called when a log message of a given severity arrives if listening
to INFO_MSG, NOTICE_MSG, WARN_MSG, or ERR_MSG events.
or_conn_status_event(self, event)
Called when an OR connection's status changes if listening to
ORCONNSTATUS events.
unknown_event(self, event)
Called when we get an event type we don't recognize.  This
is almost alwyas an error.

 
class StatsRouter(TorCtl.TorCtl.Router)
    Extended Router to handle statistics markup
 
  Methods defined here:
__init__(self, router)
'Promotion Constructor' that converts a Router directly into a 
StatsRouter without a copy.
__str__(self)
avg_extend_time(self)
Return the average amount of time it took for this router
to extend a circuit one hop
bw_ratio(self)
Return the ratio of the Router's advertised bandwidth to its 
observed average stream bandwidth
current_uptime(self)
failed_per_hour(self)
Return the number of circuit extend failures per hour for this 
Router
reset(self)
Reset all stats on this Router
sanity_check(self)
Makes sure all stats are self-consistent
suspected_per_hour(self)
Return the number of circuits that failed with this router as an
earlier hop

Data and other attributes defined here:
key = 'Metatroller Statistics:\n CC=Circuits Chosen C...z-test value\n PR=Prob(z-ratio) U=Uptime (h)\n'

Methods inherited from TorCtl.TorCtl.Router:
update_to(self, new)
Somewhat hackish method to update this router to be a copy of
'new'
will_exit_to(self, ip, port)
Check the entire exitpolicy to see if the router will allow
connections to 'ip':'port'

Data and other attributes inherited from TorCtl.TorCtl.Router:
build_from_desc = <TorCtl.TorUtil.Callable instance at 0x9b61b8c>

 
class SuspectRouterList(ReasonRouterList)
    Helper class to track all routers suspected of failing for a given
reason. The main difference between this and the normal
ReasonRouterList is the sort order and the verification.
 
  Methods defined here:
__init__(self, reason)
sort_list(self)

Methods inherited from ReasonRouterList:
add_r(self, r)
Add a router to the list for this reason
total_failed(self)
Get a list of total failures for this reason
total_suspected(self)
Get a list of total suspected failures for this reason
write_list(self, f)
Write the list of failure counts for this reason 'f'

 
Data
        control_host = '127.0.0.1'
control_port = 9051
meta_host = '127.0.0.1'
meta_port = 9052