Data distribution by frequency
Darrell Gallion
darrell at dorb.com
Sun Oct 8 01:50:21 EDT 2000
The idea of measuring the network sounded like fun.
So here's some quickie code to do some mapping.
--Darrell
import re, string, os, cPickle, time
import threading, Queue
exitAllThreads=0
class TraceThread(threading.Thread):
def __init__(self, args):
threading.Thread.__init__(self)
self._outQueue=Queue.Queue(100)
self._args=args
def run(self):
dest, sleepTime = self._args
self._name=dest
while exitAllThreads==0:
buf=os.popen("tracert -d %s"%dest).read()
if not self._outQueue.full():
self._outQueue.put(buf)
time.sleep(sleepTime)
class TraceRt:
def __init__(self, destList, sleepTime):
self._destThreads=[]
for d in destList:
th=TraceThread((d, sleepTime))
th.start()
self._destThreads.append(th)
self._stats={}
def procStats(self, buf):
res=re.findall("((?:\s+<?\d+ ms){3,3})\s+([\d.]+)", buf)
self._lastNode=""
for r in res:
t1 =re.match("\s+<?(\d+)", r[0]).group(1)
dest=r[1]
self._stats.setdefault((self._lastNode, dest),
[]).append((time.time(),eval(t1)))
self._lastNode=dest
def run(self, sleepTime):
while 1:
for th in self._destThreads:
if not th._outQueue.empty():
print th._name
buf=th._outQueue.get()
self.procStats(buf)
time.sleep(sleepTime)
fp=open("stats.dat",'w')
p=cPickle.Pickler(fp)
p.dump(self._stats)
fp.close()
# global exitAllThreads
# exitAllThreads=1
destList=["yahoo.com", "python.org"]
traceRt=TraceRt(destList, 120)
traceRt.run(60)
#########################
>>> from cPickle import *
>>> p=load(open("stats.dat"))
>>> for k, v in p.items():
... print k, v
...
...
('206.41.19.77', '208.50.169.86') [(970983801.78100002, 93)]
('157.130.219.121', '152.63.22.74') [(970983801.78100002, 10)]
('12.126.119.10', '206.41.19.77') [(970983801.78100002, 31)]
('206.204.250.130', '206.204.200.2') [(970983801.78100002, 15)]
# (source, dest)[(current time, time between nodes)]
More information about the Python-list
mailing list