]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
Merge pull request #49303 from neesingh-rh/wip-57971-pacific
authorYuri Weinstein <yweinste@redhat.com>
Tue, 14 Mar 2023 15:43:19 +0000 (08:43 -0700)
committerGitHub <noreply@github.com>
Tue, 14 Mar 2023 15:43:19 +0000 (08:43 -0700)
pacific: cephfs-top: addition of sort feature and limit option

Reviewed-by: Jos Collin <jcollin@redhat.com>
Reviewed-by: Xiubo Li <xiubli@redhat.com>
1  2 
src/tools/cephfs/top/cephfs-top

index bb3ef49f64f4acee25d3f5eec30a6ad9d6d1612f,f59c11a77e95a5d5916790d0570d7cccbd66dae4..7104d9a441492f9e229663f166026828d805daa6
@@@ -556,18 -759,37 +759,37 @@@ class FSTop(object)
                      self.fsstats.addstr(y_coord, coord[0], "N/A", curses.A_DIM)
  
      def create_clients(self, x_coord_map, stats_json, fs_name):
+         global metrics_dict, current_states
          counters = [m.upper() for m in stats_json[GLOBAL_COUNTERS_KEY]]
          self.tablehead_y += 2
-         res = stats_json[CLIENT_METADATA_KEY].get(fs_name, {})
+         res = stats_json[GLOBAL_METRICS_KEY].get(fs_name, {})
          client_cnt = len(res)
          self.fsstats.addstr(self.tablehead_y, 0, FS_TOP_NAME_TOPL_FMT.format(
 -            fs_name=fs_name, client_count=client_cnt), curses.A_BOLD | curses.A_ITALIC)
 +            fs_name=fs_name, client_count=client_cnt), curses.A_BOLD)
          self.tablehead_y += 2
+         metrics_dict_client = metrics_dict.get(fs_name, {})
+         if len(metrics_dict) > len(fs_list):
+             stale_fs = set(metrics_dict) - set(fs_list)
+             for key in stale_fs:
+                 del metrics_dict[key]
+         if len(metrics_dict_client) > client_cnt:
+             stale_clients = set(metrics_dict_client) - set(res)
+             for key in stale_clients:
+                 del metrics_dict_client[key]
          if client_cnt:
-             for client_id, metrics in \
-                     stats_json[GLOBAL_METRICS_KEY][fs_name].items():
+             if len(metrics_dict_client) != client_cnt:
+                 sort_list = sorted(list(res.keys()))
+             else:
+                 sort_arg = current_states['last_field']
+                 sort_list = sorted(list(res.keys()),
+                                    key=lambda x: metrics_dict[fs_name].get(x, {}).get(sort_arg, 0),
+                                    reverse=True)
+             if current_states['limit'] is not None and int(current_states['limit']) < client_cnt:
+                 sort_list = sort_list[0:int(current_states['limit'])]
+             for client_id in sort_list:
                  self.create_client(
-                     client_id, metrics, counters, res[client_id],
+                     fs_name, client_id, res.get(client_id, {}), counters,
+                     stats_json[CLIENT_METADATA_KEY].get(fs_name, {}).get(client_id, {}),
                      x_coord_map, self.tablehead_y)
                  self.tablehead_y += 1