[or-cvs] r10934: Add uptime to router class. Commit a statssplitter script wh (in torflow/trunk: . TorCtl)

mikeperry at seul.org mikeperry at seul.org
Thu Jul 26 07:23:36 UTC 2007


Author: mikeperry
Date: 2007-07-26 03:23:36 -0400 (Thu, 26 Jul 2007)
New Revision: 10934

Added:
   torflow/trunk/statsplitter.py
Modified:
   torflow/trunk/TorCtl/TorCtl.py
Log:

Add uptime to router class. Commit a statssplitter script
which kicks out some statistics on the directory by
percentile.



Modified: torflow/trunk/TorCtl/TorCtl.py
===================================================================
--- torflow/trunk/TorCtl/TorCtl.py	2007-07-25 22:57:07 UTC (rev 10933)
+++ torflow/trunk/TorCtl/TorCtl.py	2007-07-26 07:23:36 UTC (rev 10934)
@@ -199,7 +199,7 @@
   def __str__(self): return self.ver_string
 
 class Router:
-  def __init__(self, idhex, name, bw, down, exitpolicy, flags, ip, version, os):
+  def __init__(self, idhex, name, bw, down, exitpolicy, flags, ip, version, os, uptime):
     self.idhex = idhex
     self.nickname = name
     self.bw = bw
@@ -210,6 +210,7 @@
     self.version = RouterVersion(version)
     self.os = os
     self.list_rank = 0 # position in a sorted list of routers.
+    self.uptime = uptime
 
   def update_to(self, new):
     if self.idhex != new.idhex:
@@ -222,6 +223,7 @@
     self.ip = new.ip
     self.version = new.version
     self.os = new.os
+    self.uptime = new.uptime
 
   def will_exit_to(self, ip, port):
     for line in self.exitpolicy:
@@ -528,6 +530,7 @@
     bw_observed = 0
     version = None
     os = None
+    uptime = 0
     if router != ns.nickname:
       plog("NOTICE", "Got different names " + ns.nickname + " vs " +
              router + " for " + ns.idhex)
@@ -539,6 +542,7 @@
       ac = re.search(r"^accept (\S+):([^-]+)(?:-(\d+))?", line)
       rj = re.search(r"^reject (\S+):([^-]+)(?:-(\d+))?", line)
       bw = re.search(r"^bandwidth \d+ \d+ (\d+)", line)
+      up = re.search(r"^uptime (\d+)", line)
       if re.search(r"^opt hibernating 1", line):
         #dead = 1 # XXX: Technically this may be stale..
         if ("Running" in ns.flags):
@@ -551,12 +555,14 @@
         bw_observed = int(bw.group(1))
       elif pl:
         version, os = pl.groups()
+      elif up:
+        uptime = int(up.group(1))
     if not bw_observed and not dead and ("Valid" in ns.flags):
       plog("INFO", "No bandwidth for live router " + ns.nickname)
     if not version or not os:
       plog("INFO", "No version and/or OS for router " + ns.nickname)
     return Router(ns.idhex, ns.nickname, bw_observed, dead, exitpolicy,
-        ns.flags, ip, version, os)
+        ns.flags, ip, version, os, uptime)
 
   def read_routers(self, nslist):
     bad_key = 0

Added: torflow/trunk/statsplitter.py
===================================================================
--- torflow/trunk/statsplitter.py	                        (rev 0)
+++ torflow/trunk/statsplitter.py	2007-07-26 07:23:36 UTC (rev 10934)
@@ -0,0 +1,78 @@
+#!/usr/bin/python
+import sys
+import socket
+from TorCtl import *
+from TorCtl.PathSupport import *
+
+TorUtil.loglevel = "NOTICE"
+
+s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+s.connect(("127.0.0.1",9051))
+c = Connection(s)
+c.debug(file("control.log", "w"))
+c.authenticate()
+nslist = c.get_network_status()
+sorted_rlist = c.read_routers(c.get_network_status())
+
+sorted_rlist.sort(lambda x, y: cmp(y.bw, x.bw))
+for i in xrange(len(sorted_rlist)): sorted_rlist[i].list_rank = i
+
+exit_rst = FlagsRestriction(["Exit"], [])
+dir_rst = FlagsRestriction(["V2Dir"], [])
+heavy_exits = OrNodeRestriction(
+      [ExitPolicyRestriction("255.255.255.255", 6881),
+      ExitPolicyRestriction("255.255.255.255", 6889),
+      ExitPolicyRestriction("255.255.255.255", 6346),
+      ExitPolicyRestriction("255.255.255.255", 25)])
+
+
+def check(start, stop):
+  pct_rst = PercentileRestriction(start, stop, sorted_rlist)
+  bw = 0
+  nodes = 0
+  exits = 0
+  exit_bw = 0
+  heavy = 0
+  dirs = 0
+  nodes_up = 0
+  up = 0
+  
+  for r in sorted_rlist:
+    if pct_rst.r_is_ok(r):
+      nodes += 1
+      bw += r.bw
+      if r.uptime > 0:
+        nodes_up += 1.0
+        up += r.uptime
+      if exit_rst.r_is_ok(r):
+        exits += 1
+        exit_bw += r.bw
+      if heavy_exits.r_is_ok(r):
+        heavy += 1
+      if dir_rst.r_is_ok(r):
+        dirs += 1
+  
+  print str(start)+"-"+str(stop)+": N: "+str(nodes)+", Bw: "+str(round(bw/(1024*1024.0), 2))+", X: "+str(exits)+", XBw: "+str(round(exit_bw/(1024*1024.0),2))+", BT: "+str(heavy)+", Dirs:"+str(dirs)+", Up: "+str(round(up/nodes_up/60/60/24, 2))
+
+
+for i in xrange(0,80,5):
+  check(i,i+5)
+
+clipped = 0
+clipped_bw = 0
+exits = 0
+nodes = 0
+bw = 0
+exit_bw = 0
+for r in sorted_rlist:
+  if r.bw > 1500000:
+    clipped +=1
+    clipped_bw += r.bw - 1500000
+  nodes += 1
+  bw += r.bw
+  if exit_rst.r_is_ok(r):
+    exits += 1
+    exit_bw += r.bw
+
+print "Nodes: "+str(nodes)+", Exits: "+str(exits)+" Total bw: "+str(round(bw/(1024.0*1024),2))+", Exit Bw: "+str(round(exit_bw/(1024.0*1024),2))
+print "Clipped: "+str(clipped)+", bw: "+str(round(clipped_bw/(1024.0*1024),2))


Property changes on: torflow/trunk/statsplitter.py
___________________________________________________________________
Name: svn:executable
   + *



More information about the tor-commits mailing list