From 9aa2181b1b7c5181fa732d96dc0d4feaaddd08d2 Mon Sep 17 00:00:00 2001 From: "jingshun.tq" <35712518+Teingi@users.noreply.github.com> Date: Thu, 21 Nov 2024 11:34:37 +0800 Subject: [PATCH] Fix some bugs for obdiag 2.6.0 dev (#562) * Fix some bugs in the analyze memory function. * fix * fix * fix --- handler/analyzer/analyze_log.py | 13 +- handler/analyzer/analyze_memory.py | 281 ++++++++++-------- .../tasks/observer/database_datasize.yaml | 43 +-- .../tasks/observer/table_datasize.yaml | 61 ++-- 4 files changed, 216 insertions(+), 182 deletions(-) diff --git a/handler/analyzer/analyze_log.py b/handler/analyzer/analyze_log.py index b15f7f6b..e88dc2a9 100644 --- a/handler/analyzer/analyze_log.py +++ b/handler/analyzer/analyze_log.py @@ -151,10 +151,15 @@ def handle_from_node(node): self.stdio.print("analyze nodes's log start. Please wait a moment...") self.stdio.start_loading('analyze start') for node in self.nodes: - if not self.is_ssh: - local_ip = NetUtils.get_inner_ip() - node = self.nodes[0] - node["ip"] = local_ip + if self.directly_analyze_files: + if nodes_threads: + break + node["ip"] = '127.0.0.1' + else: + if not self.is_ssh: + local_ip = NetUtils.get_inner_ip() + node = self.nodes[0] + node["ip"] = local_ip node_threads = threading.Thread(target=handle_from_node, args=(node,)) node_threads.start() nodes_threads.append(node_threads) diff --git a/handler/analyzer/analyze_memory.py b/handler/analyzer/analyze_memory.py index 336a03cf..8f091687 100644 --- a/handler/analyzer/analyze_memory.py +++ b/handler/analyzer/analyze_memory.py @@ -64,7 +64,8 @@ def init_config(self): self.file_number_limit = int(basic_config["file_number_limit"]) self.file_size_limit = int(FileUtil.size(basic_config["file_size_limit"])) self.config_path = basic_config['config_path'] - self.version = self.get_version() + if self.version is None: + self.version = self.get_version() return True def init_option(self): @@ -81,7 +82,11 @@ def init_option(self): self.is_ssh = False self.directly_analyze_files = True self.analyze_files_list = files_option - self.version = version + if version: + self.version = version + else: + self.stdio.error('the option --files requires the --version option to be specified') + return False if from_option is not None and to_option is not None: try: from_timestamp = TimeUtils.parse_time_str(from_option) @@ -149,16 +154,21 @@ def handle_from_node(node): with pool_sema: st = time.time() resp = self.__handle_from_node(node, local_store_parent_dir) - analyze_tuples.append((node.get("ip"), False, resp["error"], int(time.time() - st), resp["result_pack_path"])) + analyze_tuples.append((node.get("ip"), resp["skip"], resp["error"], int(time.time() - st), resp["result_pack_path"])) nodes_threads = [] self.stdio.print("analyze nodes's log start. Please wait a moment...") self.stdio.start_loading('analyze memory start') for node in self.nodes: - if not self.is_ssh: - local_ip = NetUtils.get_inner_ip() - node = self.nodes[0] - node["ip"] = local_ip + if self.directly_analyze_files: + if nodes_threads: + break + node["ip"] = '127.0.0.1' + else: + if not self.is_ssh: + local_ip = NetUtils.get_inner_ip() + node = self.nodes[0] + node["ip"] = local_ip node_threads = threading.Thread(target=handle_from_node, args=(node,)) node_threads.start() nodes_threads.append(node_threads) @@ -194,7 +204,8 @@ def __handle_from_node(self, node, local_store_parent_dir): gather_dir_full_path = "{0}/{1}".format(self.gather_ob_log_temporary_dir, gather_dir_name) mkdir(ssh_client, gather_dir_full_path) log_list, resp = self.__handle_log_list(ssh_client, node, resp) - resp["result_pack_path"] = local_store_dir + result_pack_path = "./{0}".format(os.path.relpath(local_store_dir, self.gather_pack_dir)) + resp["result_pack_path"] = result_pack_path if resp["skip"]: return resp self.stdio.print(FileUtil.show_file_list_tabulate(remote_ip, log_list, self.stdio)) @@ -229,7 +240,10 @@ def __handle_from_node(self, node, local_store_parent_dir): try: fig = go.Figure() colors = ['blue', 'orange', 'green', 'red', 'purple', 'cyan', 'magenta', 'yellow', 'black', 'brown', 'pink', 'gray', 'lime', 'teal', 'navy'] - if len(tenant_memory_info_dict) < 20: + if len(tenant_memory_info_dict) == 0: + resp["skip"] = True + resp["error"] = "failed to analyze memory data from the log" + elif len(tenant_memory_info_dict) < 20 and len(tenant_memory_info_dict) > 0: i = 0 x_lines = [] x_vals = [] @@ -312,61 +326,61 @@ def __handle_from_node(self, node, local_store_parent_dir): html_fig_ctx = pio.to_html(fig_ctx, full_html=False) html_fig_mod = pio.to_html(fig_mod, full_html=False) html_combined = ''' - -
-