Browse files

Better formatting for status

  • Loading branch information...
1 parent fefb983 commit a629fe8032a134d27a534f0744ceb402550d1352 @rhettg committed Mar 19, 2012
Showing with 16 additions and 2 deletions.
  1. +16 −2 bin/ziggyctl
View
18 bin/ziggyctl
@@ -1,7 +1,10 @@
#!/bin/python
import argparse
+import datetime
import sys
+import time
import logging
+import pprint
import zmq
import bson
@@ -24,6 +27,7 @@ def main():
parser = argparse.ArgumentParser()
parser.add_argument('--verbose', '-v', dest='verbose', action='append_const', const=True, default=list())
parser.add_argument('--host', '-H', dest='host', action='store', default="127.0.0.1:3513")
+ parser.add_argument('--raw', '-r', dest='raw', action='store_true', default=False)
options = parser.parse_args()
@@ -40,8 +44,18 @@ def main():
result = dict(poller.poll(5000))
if sock in result:
resp = bson.loads(sock.recv())
- # TODO: Some formatting options
- import pprint; pprint.pprint(resp)
+ if options.raw:
+ print resp
+ else:
+ print "Host: %s" % options.host
+ if 'last' in resp:
+ print "Last: %s (%d secs ago)" % (datetime.datetime.fromtimestamp(resp['last']), time.time() - resp['last'])
+ if 'lag' in resp:
+ print "Lag: %f secs" % resp['lag']
+
+ print
+ for name, name_data in resp['events'].iteritems():
+ print " %32s Last %s (%d secs ago)" % (name, datetime.datetime.fromtimestamp(name_data['last']), time.time() - name_data['last'])
else:
print >>sys.stderr, "Error connecting to server"
sys.exit(1)

0 comments on commit a629fe8

Please sign in to comment.