From abd4ae9f9b1bdf1f4d7ee7b10baa9c8ec03303fc Mon Sep 17 00:00:00 2001 From: Rachana Patel Date: Tue, 23 Mar 2021 04:40:56 +0000 Subject: [PATCH] cephfs-top: allow configurable stats refresh interval Signed-off-by: Rachana Patel --- doc/cephfs/cephfs-top.rst | 6 ++++++ src/tools/cephfs/top/cephfs-top | 17 ++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/doc/cephfs/cephfs-top.rst b/doc/cephfs/cephfs-top.rst index 200ca1504f8..47e80df9d2f 100644 --- a/doc/cephfs/cephfs-top.rst +++ b/doc/cephfs/cephfs-top.rst @@ -70,6 +70,12 @@ By default, `cephfs-top` connects to cluster name `ceph`. To use a non-default c $ cephfs-top --cluster +`cephfs-top` refreshes stats every second by default. To chose a different refresh interval use:: + + $ cephfs-top -d + +Interval should be greater or equal to 0.5 second. Fractional seconds are honoured. + Sample screenshot running `cephfs-top` with 2 clients: .. image:: cephfs-top.png diff --git a/src/tools/cephfs/top/cephfs-top b/src/tools/cephfs/top/cephfs-top index f5a74b82645..917057cd873 100755 --- a/src/tools/cephfs/top/cephfs-top +++ b/src/tools/cephfs/top/cephfs-top @@ -37,6 +37,9 @@ FS_TOP_SUPPORTED_VER = 1 ITEMS_PAD_LEN = 1 ITEMS_PAD = " " * ITEMS_PAD_LEN +DEFAULT_REFRESH_INTERVAL = 1 +# min refresh interval allowed +MIN_REFRESH_INTERVAL = 0.5 # metadata provided by mgr/stats FS_TOP_MAIN_WINDOW_COL_CLIENT_ID = "CLIENT_ID" @@ -98,6 +101,7 @@ class FSTop(object): self.client_name = args.id self.cluster_name = args.cluster self.conffile = args.conffile + self.refresh_interval_secs = args.delay def handle_signal(self, signum, _): self.stop = True @@ -279,10 +283,17 @@ class FSTop(object): self.refresh_main_window(x_coord_map, stats_json) self.header.refresh() self.mainw.refresh() - time.sleep(1) + time.sleep(self.refresh_interval_secs) if __name__ == '__main__': + def float_greater_than(x): + value = float(x) + if value < MIN_REFRESH_INTERVAL: + raise argparse.ArgumentTypeError(f'{value} should be greater than ' + f'{MIN_REFRESH_INTERVAL}') + return value + parser = argparse.ArgumentParser(description='Ceph Filesystem top utility') parser.add_argument('--cluster', nargs='?', const='ceph', default='ceph', help='Ceph cluster to connect (defualt: ceph)') @@ -292,6 +303,10 @@ if __name__ == '__main__': help='Path to cluster configuration file') parser.add_argument('--selftest', dest='selftest', action='store_true', help='run in selftest mode') + parser.add_argument('-d', '--delay', nargs='?', default=DEFAULT_REFRESH_INTERVAL, + type=float_greater_than, help='Interval to refresh data ' + f'(default: {DEFAULT_REFRESH_INTERVAL})') + args = parser.parse_args() err = False ft = FSTop(args)