From: Mykola Golub Date: Mon, 19 Nov 2018 09:23:51 +0000 (+0200) Subject: mgr/osd_perf_query: example how limit can be used X-Git-Tag: v14.1.0~719^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=5561ffc86421bc3f18e2b830c244d2e9808fddd7;p=ceph.git mgr/osd_perf_query: example how limit can be used Signed-off-by: Mykola Golub --- diff --git a/src/pybind/mgr/osd_perf_query/module.py b/src/pybind/mgr/osd_perf_query/module.py index 56604d44b844..4e293b4e1a32 100644 --- a/src/pybind/mgr/osd_perf_query/module.py +++ b/src/pybind/mgr/osd_perf_query/module.py @@ -46,9 +46,10 @@ class OSDPerfQuery(MgrModule): {'type': 'client_id', 'regex': '^.+$'}, ], 'performance_counter_descriptors': [ - 'write_ops', 'read_ops', 'write_bytes', 'read_bytes', + 'bytes', 'write_ops', 'read_ops', 'write_bytes', 'read_bytes', 'write_latency', 'read_latency', ], + 'limit': {'order_by': 'bytes', 'max_count': 10}, } RBD_IMAGE_ID_QUERY = { @@ -57,9 +58,10 @@ class OSDPerfQuery(MgrModule): {'type': 'object_name', 'regex': '^rbd_data\.([^.]+)\.'}, ], 'performance_counter_descriptors': [ - 'write_ops', 'read_ops', 'write_bytes', 'read_bytes', + 'bytes', 'write_ops', 'read_ops', 'write_bytes', 'read_bytes', 'write_latency', 'read_latency', ], + 'limit': {'order_by': 'bytes', 'max_count': 10}, } queries = {} @@ -97,7 +99,9 @@ class OSDPerfQuery(MgrModule): column_names = ["client_id"] for d in descriptors: desc = d - if d in ['write_bytes', 'read_bytes']: + if d in ['bytes']: + continue + elif d in ['write_bytes', 'read_bytes']: desc += '/sec' elif d in ['write_latency', 'read_latency']: desc += '(msec)' @@ -105,14 +109,24 @@ class OSDPerfQuery(MgrModule): table = prettytable.PrettyTable(tuple(column_names), hrules=prettytable.FRAME) - for c in res['counters']: + + max_count = len(res['counters']) + if 'limit' in query: + if 'max_count' in query['limit']: + max_count = query['limit']['max_count'] + if 'order_by' in query['limit']: + i = descriptors.index(query['limit']['order_by']) + res['counters'].sort(key=lambda x: x['c'][i], reverse=True) + for c in res['counters'][:max_count]: if query == self.RBD_IMAGE_ID_QUERY: row = [c['k'][0][0], c['k'][1][1]] else: row = [c['k'][0][0]] counters = c['c'] for i in range(len(descriptors)): - if descriptors[i] in ['write_bytes', 'read_bytes']: + if descriptors[i] in ['bytes']: + continue + elif descriptors[i] in ['write_bytes', 'read_bytes']: bps = counters[i][0] / (now - last_update) row.append(get_human_readable(bps)) elif descriptors[i] in ['write_latency', 'read_latency']: