From 8a5553597ca6a428cb8ffc9fc5bebde048fbd068 Mon Sep 17 00:00:00 2001 From: Nico Wang Date: Tue, 10 Oct 2023 21:00:29 +0000 Subject: [PATCH] mgr/balancer: Improved 'ceph balancer status' output We have recently introduced a detailed command to check the status of our balancer. This command displays the location of pg_up_map items where they are being transferred when the balancer runs. The primary objective of this command is to obtain a better understanding of the balancer's behavior in terms of transferring pgs. This will help us identify when the balancing is taking place in the effort to improve the balancing process to evenly distribute pgs in the balancing process. Signed-off-by: Christopher Poon Signed-off-by: Zuriel Aviles Signed-off-by: Nico Wang --- src/pybind/mgr/balancer/module.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/pybind/mgr/balancer/module.py b/src/pybind/mgr/balancer/module.py index 1c40425115c..590f24653f0 100644 --- a/src/pybind/mgr/balancer/module.py +++ b/src/pybind/mgr/balancer/module.py @@ -327,6 +327,9 @@ class Module(MgrModule): no_optimization_needed = False success_string = 'Optimization plan created successfully' in_progress_string = 'in progress' + last_pg_upmap: List[Dict[str, Any]] = [] + added_pg_upmap_items: List[Dict[str, Any]] = [] + removed_pg_upmap_items: List[Dict[str, Any]] = [] def __init__(self, *args: Any, **kwargs: Any) -> None: super(Module, self).__init__(*args, **kwargs) @@ -348,6 +351,24 @@ class Module(MgrModule): } return (0, json.dumps(s, indent=4, sort_keys=True), '') + @CLIReadCommand('balancer status detail') + def show_status_detail(self) -> Tuple[int, str, str]: + """ + Show balancer status (detailed) + """ + s = { + 'plans': list(self.plans.keys()), + 'active': self.active, + 'last_optimize_started': self.last_optimize_started, + 'last_optimize_duration': self.last_optimize_duration, + 'optimize_result': self.optimize_result, + 'no_optimization_needed': self.no_optimization_needed, + 'mode': self.get_module_option('mode'), + 'added_pg_upmap_items': self.added_pg_upmap_items, + 'removed_pg_upmap_items': self.removed_pg_upmap_items, + } + return (0, json.dumps(s, indent=4), '') + @CLICommand('balancer mode') def set_mode(self, mode: Mode) -> Tuple[int, str, str]: """ @@ -693,6 +714,9 @@ class Module(MgrModule): start = time.time() r, detail = self.optimize(plan) end = time.time() + self.added_pg_upmap_items = [pg for pg in osdmap.dump().get('pg_upmap_items', '') if pg not in self.last_pg_upmap] + self.removed_pg_upmap_items = [pg for pg in self.last_pg_upmap if pg not in osdmap.dump().get('pg_upmap_items', '')] + self.last_pg_upmap = osdmap.dump().get('pg_upmap_items', '') self.last_optimize_duration = str(datetime.timedelta(seconds=(end - start))) if r == 0: self.optimize_result = self.success_string -- 2.39.5