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 e532107c..c4968468 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) @@ -155,10 +160,15 @@ def handle_from_node(node): 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) @@ -230,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 = [] @@ -313,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 = ''' - - - tenant-{0}_hold_memory - - - -
- - - - - - - - - - - - - - - - -
-
- {1} -
- {2} -
- {3} - - -'''.format( + header>svg {{ + margin-left: -2em; + }} + + + +
+ + + + + + + + + + + + + + + + +
+
+ {1} +
+ {2} +
+ {3} + + + '''.format( tenant_id, html_fig_tenant, html_fig_ctx, html_fig_mod ) with open('{0}/tenant-{1}_hold_memory.html'.format(local_store_dir, tenant_id), 'w') as f: @@ -378,62 +391,61 @@ def __handle_from_node(self, node, local_store_parent_dir): fig.update_yaxes(tickformat='.0f') html_fig = pio.to_html(fig, full_html=False) html_top15_combined = ''' - - - TOP 15租户hold内存曲线图 - - - -
- - - - - - - - - - - - - - - - -
-
- {0} - - -'''.format( + header>svg {{ + margin-left: -2em; + }} + + + +
+ + + + + + + + + + + + + + + + +
+
+ {0} + + + '''.format( html_fig ) with open('{0}/TOP15_tenant_hold_memory.html'.format(local_store_dir), 'w') as f: f.write(html_top15_combined) - # plot(fig, filename='{0}/TOP15_tenant_hold_memory.html'.format(local_store_dir)) except Exception as e: self.stdio.exception('write html result failed, error: {0}'.format(e)) delete_file(ssh_client, gather_dir_full_path, self.stdio) @@ -534,7 +546,9 @@ def __pharse_offline_log_file(self, ssh_client, log_name, local_store_dir): def __parse_memory_label(self, file_full_path): ssh_client = ssh_client_local_client.LocalClient(context=self.context, node={"ssh_type": "local"}) - if self.version > '4.0': + if self.version >= '4.3': + grep_cmd = 'grep -n "memory_dump.*statistics" ' + file_full_path + elif self.version >= '4.0' and self.version < '4.3': grep_cmd = 'grep -n "runTimerTask.*MemDumpTimer" ' + file_full_path else: grep_cmd = 'grep -n "Run print tenant memstore usage task" ' + file_full_path @@ -582,7 +596,12 @@ def __parse_log_lines(self, file_full_path, memory_dict): if line_num < memory_print_begin_line: continue else: - if self.version > '4.0': + if self.version >= '4.3': + if 'MemoryDump' in line and 'statistics' in line: + time_str = self.__get_time_from_ob_log_line(line) + memory_print_time = time_str.split('.')[0] + memory_dict[memory_print_time] = dict() + elif self.version > '4.0' and self.version < '4.3' : if 'runTimerTask' in line and 'MemDumpTimer' in line: time_str = self.__get_time_from_ob_log_line(line) memory_print_time = time_str.split('.')[0] @@ -592,7 +611,14 @@ def __parse_log_lines(self, file_full_path, memory_dict): time_str = self.__get_time_from_ob_log_line(line) memory_print_time = time_str.split('.')[0] memory_dict[memory_print_time] = dict() - if self.version > '4.0': + if self.version >= '4.3': + if 'print_tenant_usage' in line and 'ServerGTimer' in line and 'CHUNK_MGR' in line: + if memory_print_line_list: + memory_print_begin_line = memory_print_line_list[0] + memory_print_line_list.remove(memory_print_begin_line) + else: + break + elif self.version >= '4.0' and self.version < '4.3' : if 'print_tenant_usage' in line and 'MemDumpTimer' in line and 'CHUNK_MGR' in line: if memory_print_line_list: memory_print_begin_line = memory_print_line_list[0] @@ -606,7 +632,7 @@ def __parse_log_lines(self, file_full_path, memory_dict): memory_print_line_list.remove(memory_print_begin_line) else: break - if '[MEMORY]' in line or 'MemDumpTimer' in line or 'ob_tenant_ctx_allocator' in line: + if '[MEMORY]' in line or 'MemDump' in line or 'ob_tenant_ctx_allocator' in line: if '[MEMORY] tenant:' in line: tenant_id = line.split('tenant:')[1].split(',')[0].strip() hold_bytes = line.split('hold:')[1].split('rpc_')[0].strip()