Commit 555dd4d2 authored by Kazunori Fujiwara's avatar Kazunori Fujiwara
Browse files

First statistics test:

  respondent.py has single "counter".
  collector.py collects data and output them to stdout


git-svn-id: svn://bind10.isc.org/svn/bind10/branches/f2f200910@149 e5f2f494-b856-4b98-b285-d166d9295462
parent 66ff25c0
import ISC
import time
import select
timeout = 1
tcp = ISC.CC.Session()
print tcp.lname
tcp.group_subscribe("statistics")
sent = time.time()
tcp.group_sendmsg({ "command": "whoareyou"}, "statistics")
print "SEND: whoareyou"
while (sent + timeout - time.time()) > 0:
wait = sent + timeout - time.time()
print "wait=",wait
r,w,e = select.select([tcp._socket],[],[], wait)
for sock in r:
if sock == tcp._socket:
data,envelope = tcp.group_recvmsg(False);
print "data:", data
print ""
loop = 0
while loop < 10000:
print "loop=", loop, " SEND: getstat"
sent = time.time();
tcp.group_sendmsg({ "command": "getstat"}, "statistics")
while (sent + timeout - time.time()) > 0:
wait = sent + timeout - time.time()
r,w,e = select.select([tcp._socket],[],[], wait)
for sock in r:
if sock == tcp._socket:
data,envelope = tcp.group_recvmsg(False);
print envelope["from"], " : ", data
loop += 1
#!/usr/bin/python
# This program acts statistics respondent.
# It has pseudo "counter" which is incremented each 0.3 second and C-channel query.
# Two command is available
# "whoareyou"
# "getstat"
import ISC
import socket
import select
import time
statgroup = "statistics"
cc = ISC.CC.Session()
print cc.lname
cc.group_subscribe(statgroup)
counter = 0
while 1:
r,w,e = select.select([cc._socket],[],[],0.3)
counter += 1
for sock in r:
if sock == cc._socket:
data,envelope = cc.group_recvmsg(False);
if (envelope["group"] == statgroup):
print data["command"]
if (data["command"] == "whoareyou"):
cc.group_reply(envelope, {"name": cc.lname })
elif (data["command"] == "getstat"):
cc.group_reply(envelope, {"timestamp": time.time(), "counter":counter})
# Do another group
# Do another socket
# Do main work
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment