[svn] commit: r179 - in /branches/f2f200910/src/bin/statistics-test: boss-shutdown.py collector.py respondent.py
BIND 10 source code commits
bind10-changes at lists.isc.org
Thu Oct 29 21:51:12 UTC 2009
Author: fujiwara
Date: Thu Oct 29 21:51:12 2009
New Revision: 179
Log:
An example statistics respondent accepts two command:
"statistics" group "getstat"
"Boss" group "shutdown"
An example statistics collector send "getstat" command to "statistics" group.
It also accepts "Boss" group "shutdown" command.
Added:
branches/f2f200910/src/bin/statistics-test/boss-shutdown.py
Modified:
branches/f2f200910/src/bin/statistics-test/collector.py
branches/f2f200910/src/bin/statistics-test/respondent.py
Modified: branches/f2f200910/src/bin/statistics-test/collector.py
==============================================================================
--- branches/f2f200910/src/bin/statistics-test/collector.py (original)
+++ branches/f2f200910/src/bin/statistics-test/collector.py Thu Oct 29 21:51:12 2009
@@ -1,39 +1,59 @@
+#!/usr/bin/python
+#
+# This program collects "counter" from "statistics" channel.
+# It accepts one command: "Boss" group "shutdown"
+
import ISC
import time
import select
-timeout = 1
+step_time = 1
+statgroup = "statistics"
-tcp = ISC.CC.Session()
-print tcp.lname
+cc = ISC.CC.Session()
+print cc.lname
+cc.group_subscribe(statgroup)
+cc.group_subscribe("Boss")
-tcp.group_subscribe("statistics")
+server_by_name = {}
+server_by_id = []
+counter = []
+timestamp = []
+servers = 0
-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)
+sent = -1
+last_sent = -1
+loop = 0
+while 1:
+ wait = sent + step_time - time.time()
+ if wait <= 0:
+ sent = time.time();
+ command = { "command": "getstat", "sent":time.time() }
+ print "loop=", loop, " SEND: ", command
+ cc.group_sendmsg(command, "statistics")
+ wait = last_sent + step_time - time.time()
+ if wait < 0:
+ wait = step_time
+ loop += 1
+ r,w,e = select.select([cc._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
+ if sock == cc._socket:
+ data,envelope = cc.group_recvmsg(False)
+ if (envelope["group"] == "Boss"):
+ if (data["command"] == "shutdown"):
+ exit()
+ if (envelope["group"] == statgroup):
+ if (envelope["from"] in server_by_name):
+ id = server_by_name[envelope["from"]]
+ delta_t = float(data["sent"]) - float(timestamp[id])
+ delta_c = float(data["counter"]) - float(counter[id])
+ print "server",id," time=",data["sent"], " counter=", data["counter"], " dT=", delta_t, " dC=", delta_c
+ timestamp[id] = data["sent"]
+ counter[id] = data["counter"]
+ else:
+ print "server ", servers, " name ", envelope["from"]
+ server_by_id.append(envelope["from"])
+ server_by_name[envelope["from"]] = len(server_by_id) - 1
+ counter.append(data["counter"])
+ timestamp.append(data["sent"])
+ servers += 1
Modified: branches/f2f200910/src/bin/statistics-test/respondent.py
==============================================================================
--- branches/f2f200910/src/bin/statistics-test/respondent.py (original)
+++ branches/f2f200910/src/bin/statistics-test/respondent.py Thu Oct 29 21:51:12 2009
@@ -3,34 +3,40 @@
# 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"
+# "statistics" group: "getstat"
+# "Boss" group: "shutdown"
import ISC
-import socket
import select
-import time
+import random
statgroup = "statistics"
cc = ISC.CC.Session()
-print cc.lname
+print (cc.lname)
cc.group_subscribe(statgroup)
+cc.group_subscribe("Boss")
counter = 0
while 1:
- r,w,e = select.select([cc._socket],[],[],0.3)
- counter += 1
+ r,w,e = select.select([cc._socket],[],[])
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})
+ if (data["command"] == "getstat"):
+ cc.group_reply(envelope,
+ {
+ "response":data["command"],
+ "sent": data["sent"],
+ "counter":counter
+ })
+ # Do another statistics command
+ elif (envelope["group"] == "Boss"):
+ if (data["command"] == "shutdown"):
+ exit()
# Do another group
# Do another socket
# Do main work
+ counter += random.randrange(1,100)
More information about the bind10-changes
mailing list