commit 2fc173a76b7ba097561955aa39db5407e539e5f7
parent fb5ceb5167db2eef4d281b71121e23dfa71e3e29
Author: ThomasV <thomasv@gitorious>
Date: Sun, 14 Oct 2012 18:31:08 +0200
new script showing server status
Diffstat:
1 file changed, 37 insertions(+), 0 deletions(-)
diff --git a/scripts/servers b/scripts/servers
@@ -0,0 +1,37 @@
+#!/usr/bin/env python
+
+from electrum import Interface, DEFAULT_SERVERS
+import time, Queue
+
+servers = DEFAULT_SERVERS
+interfaces = map ( lambda server: Interface({'server':server} ), servers )
+results = []
+
+for i in interfaces:
+ if i.is_connected:
+ i.start()
+ i.send([('blockchain.numblocks.subscribe',[])])
+ else:
+ servers.remove(i.server)
+
+while servers:
+ for i in interfaces:
+ try:
+ r = i.responses.get(False)
+ except Queue.Empty:
+ continue
+
+ if r.get('method') == 'blockchain.numblocks.subscribe':
+ results.append((i.host, r.get('result')))
+ servers.remove(i.server)
+
+from collections import defaultdict
+d = defaultdict(int)
+for e in results:
+ d[e[1]] += 1
+v = d.values()
+numblocks = d.keys()[v.index(max(v))]
+
+for s,n in results:
+ print "%30s %d "%(s, n), "ok" if abs(n-numblocks)<2 else "lagging"
+