From be550862baf75eed89c983a5d7c6d0c06e8f83d7 Mon Sep 17 00:00:00 2001 From: Feng Shengqin Date: Tue, 23 May 2017 13:38:49 +0800 Subject: [PATCH] Compile stats on server side Currently, we let server to return the raw stats and compile them at client side. It would be better to move the compilation of stats from zunclient to server. At zunclient, it should just print whatever output server returned. Change-Id: I893bf32cd43f0be89dac87d01e3ce6e1845578c1 Related-Bug: #1692732 --- zunclient/osc/v1/containers.py | 34 ++------------------------------ zunclient/v1/containers_shell.py | 34 ++------------------------------ 2 files changed, 4 insertions(+), 64 deletions(-) diff --git a/zunclient/osc/v1/containers.py b/zunclient/osc/v1/containers.py index 129ae64f..34a81217 100644 --- a/zunclient/osc/v1/containers.py +++ b/zunclient/osc/v1/containers.py @@ -809,35 +809,5 @@ class StatsContainer(command.Command): def take_action(self, parsed_args): client = _get_client(self, parsed_args) container = parsed_args.container - res = client.containers.stats(container) - cpu_usage = res['cpu_stats']['cpu_usage']['total_usage'] - system_cpu_usage = res['cpu_stats']['system_cpu_usage'] - cpu_percent = float(cpu_usage) / float(system_cpu_usage) * 100 - mem_usage = res['memory_stats']['usage'] / 1024 / 1024 - mem_limit = res['memory_stats']['limit'] / 1024 / 1024 - mem_percent = float(mem_usage) / float(mem_limit) * 100 - - blk_stats = res['blkio_stats']['io_service_bytes_recursive'] - io_read = 0 - io_write = 0 - for item in blk_stats: - if 'Read' == item['op']: - io_read = io_read + item['value'] - if 'Write' == item['op']: - io_write = io_write + item['value'] - - net_stats = res['networks'] - net_rxb = 0 - net_txb = 0 - for k, v in net_stats.items(): - net_rxb = net_rxb + v['rx_bytes'] - net_txb = net_txb + v['tx_bytes'] - - stats = {"CONTAINER": container, - "CPU %": cpu_percent, - "MEM USAGE(MiB)": mem_usage, - "MEM LIMIT(MiB)": mem_limit, - "MEM %": mem_percent, - "BLOCK I/O(B)": str(io_read) + "/" + str(io_write), - "NET I/O(B)": str(net_rxb) + "/" + str(net_txb)} - cliutils.print_dict(stats) + stats_info = client.containers.stats(container) + cliutils.print_dict(stats_info) diff --git a/zunclient/v1/containers_shell.py b/zunclient/v1/containers_shell.py index 30412f1b..500627f5 100644 --- a/zunclient/v1/containers_shell.py +++ b/zunclient/v1/containers_shell.py @@ -564,35 +564,5 @@ def do_cp(cs, args): help='ID or name of the container to display stats.') def do_stats(cs, args): """Display stats snapshot of the container.""" - res = cs.containers.stats(args.container) - cpu_usage = res['cpu_stats']['cpu_usage']['total_usage'] - system_cpu_usage = res['cpu_stats']['system_cpu_usage'] - cpu_percent = float(cpu_usage) / float(system_cpu_usage) * 100 - mem_usage = res['memory_stats']['usage'] / zun_utils.M - mem_limit = res['memory_stats']['limit'] / zun_utils.M - mem_percent = float(mem_usage) / float(mem_limit) * 100 - - blk_stats = res['blkio_stats']['io_service_bytes_recursive'] - io_read = 0 - io_write = 0 - for item in blk_stats: - if 'Read' == item['op']: - io_read = io_read + item['value'] - if 'Write' == item['op']: - io_write = io_write + item['value'] - - net_stats = res['networks'] - net_rxb = 0 - net_txb = 0 - for k, v in net_stats.items(): - net_rxb = net_rxb + v['rx_bytes'] - net_txb = net_txb + v['tx_bytes'] - - stats = {"CONTAINER": args.container, - "CPU %": cpu_percent, - "MEM USAGE(MiB)": mem_usage, - "MEM LIMIT(MiB)": mem_limit, - "MEM %": mem_percent, - "BLOCK I/O(B)": str(io_read) + "/" + str(io_write), - "NET I/O(B)": str(net_rxb) + "/" + str(net_txb)} - utils.print_dict(stats) + stats_info = cs.containers.stats(args.container) + utils.print_dict(stats_info)