[svn] commit: r664 - /branches/parkinglot/src/bin/stats/statsd.py
BIND 10 source code commits
bind10-changes at lists.isc.org
Fri Jan 29 22:33:55 UTC 2010
Author: fujiwara
Date: Fri Jan 29 22:33:55 2010
New Revision: 664
Log:
Output XML file passes xmllint.
Added all components data into XML output. (using total and each tag).
Modified:
branches/parkinglot/src/bin/stats/statsd.py
Modified: branches/parkinglot/src/bin/stats/statsd.py
==============================================================================
--- branches/parkinglot/src/bin/stats/statsd.py (original)
+++ branches/parkinglot/src/bin/stats/statsd.py Fri Jan 29 22:33:55 2010
@@ -9,6 +9,7 @@
import os
bossgroup = 'Boss'
+myname = 'statsd'
def total(s):
def totalsub(d,s):
@@ -47,7 +48,7 @@
out['timestamp2'] = _time2;
return out
-def dicttoxml(stats):
+def dicttoxml(stats, level = 0):
def dicttoxmlsub(s, level):
output = ''
spaces = ' ' * level
@@ -61,21 +62,33 @@
return output
for k in stats.keys():
- output = '<component="%s">\n' % k
+ space = ' ' * level
+ output = space + '<component component="%s">\n' % k
s = stats[k]
if ('component' in s or 'components' in s):
- output = output + dicttoxmlsub(s, 1)
+ output += dicttoxmlsub(s, level+1)
else:
for l in s.keys():
- output += ' <from="%s">\n' % l \
- + dicttoxmlsub(s[l], 2) \
- + ' </from>\n'
- output += '</component>\n'
+ output += space + ' <from from="%s">\n' % l \
+ + dicttoxmlsub(s[l], level+2) \
+ + space + ' </from>\n'
+ output += space + '</component>\n'
return output
-def dump_stats(statpath, statcount, stat):
+def dump_stats(statpath, statcount, stat, statraw):
newfile = open(statpath + '.new', 'w')
- newfile.write(dicttoxml(stat))
+ newfile.write('<?xml version="1.0" encoding="UTF-8"?>\n')
+ newfile.write('<!-- created at '+time.strftime('%Y%m%d %H%M%S')+' -->\n')
+ newfile.write('<isc version="0.0">\n')
+ newfile.write(' <bind10>\n')
+ newfile.write(' <total>\n')
+ newfile.write(dicttoxml(stat, 3))
+ newfile.write(' </total>\n')
+ newfile.write(' <each>\n')
+ newfile.write(dicttoxml(statraw, 3))
+ newfile.write(' </each>\n')
+ newfile.write(' </bind10>\n')
+ newfile.write('</isc>\n')
newfile.close()
loop = statcount
while(loop > 0):
@@ -92,7 +105,7 @@
cc = ISC.CC.Session()
print (cc.lname)
cc.group_subscribe(statgroup)
- cc.group_subscribe(bossgroup)
+ cc.group_subscribe(bossgroup, myname)
wrote_time = -1
last_wrote_time = -1
last_recvd_time = -1
@@ -101,7 +114,7 @@
while 1:
wait = wrote_time + step - time.time()
if wait <= 0 and last_recvd_time > wrote_time:
- dump_stats(statpath, statcount, statstotal)
+ dump_stats(statpath, statcount, statstotal, stats)
last_wrote_time = wrote_time;
wrote_time = time.time();
wait = last_wrote_time + step - time.time()
@@ -111,7 +124,7 @@
for sock in r:
if sock == cc._socket:
data,envelope = cc.group_recvmsg(False)
- if (envelope['group'] == 'Boss'):
+ if (envelope['group'] == bossgroup):
if ('shutdown' in data):
exit()
if (envelope['group'] == statgroup):
More information about the bind10-changes
mailing list