浏览代码

command moni with two columns print formatting

Daniel-Constantin Mierla 8 年之前
父节点
当前提交
7b98b3826d
共有 1 个文件被更改,包括 19 次插入3 次删除
  1. 19 3
      kamcli/commands/cmd_moni.py

+ 19 - 3
kamcli/commands/cmd_moni.py

@@ -1,6 +1,7 @@
 import os
 import time
 import click
+import json
 from kamcli.cli import pass_context
 from kamcli.iorpc import command_ctl
 
@@ -26,14 +27,29 @@ def cli(ctx, norefresh):
     clear = lambda : os.system('tput reset')
     count = 0
     slist = [ "rcv_requests", "fwd_requests", "rcv_replies", "fwd_replies",
-            "sent_replies", "tmx:", "usrloc:" ]
+            "free_size", "sent_replies", "tmx:", "usrloc:" ]
     if norefresh is True:
-        command_ctl(ctx, 'stats.get_statistics', slist)
+        command_ctl(ctx, 'stats.get_statistics', slist, {"func": cmd_moni_result_print})
     else:
         while True:
             count = count + 1
-            command_ctl(ctx, 'stats.get_statistics', slist)
+            command_ctl(ctx, 'stats.get_statistics', slist, {"func": cmd_moni_result_print})
+            print
             print "[cycle #: " + str(count) + "; if constant make sure server is running]"
             time.sleep(2)
             clear()
 
+
+##
+#
+#
+def cmd_moni_result_print(ctx, response, params=None):
+    ctx.vlog("formatting the response for command ps")
+    print
+    rdata = json.loads(response)
+    if "result" in rdata:
+        rd = rdata["result"]
+        for a,b in zip(rd[::2],rd[1::2]):
+            print '{:<40}{:<}'.format(a,b)
+    else:
+        print json.dumps(rdata, indent=4, separators=(',', ': '))