diff --git a/handler/gather/gather_plan_monitor.py b/handler/gather/gather_plan_monitor.py index 81ec817a..f856c6b2 100644 --- a/handler/gather/gather_plan_monitor.py +++ b/handler/gather/gather_plan_monitor.py @@ -148,6 +148,8 @@ def handle_plan_monitor_from_ob(cluster_name): sql_plan_monitor_detail_v2 = str(sql_plan_monitor_detail_template).replace("##REPLACE_TRACE_ID##", trace_id).replace("##REPLACE_ORDER_BY##", "PROCESS_NAME ASC, PLAN_LINE_ID ASC, FIRST_REFRESH_TIME ASC") sql_plan_monitor_dfo_op = self.sql_plan_monitor_dfo_op_sql(tenant_id, plan_id, trace_id, svr_ip, svr_port) + sql_ash_top_event = self.sql_ash_top_event_sql(tenant_id, trace_id) + sql_plan_monitor_db_time = self.sql_plan_monitor_db_time_sql(tenant_id, trace_id) full_audit_sql_by_trace_id_sql = self.full_audit_sql_by_trace_id_sql(trace_id) plan_explain_sql = self.plan_explain_sql(tenant_id, plan_id, svr_ip, svr_port) @@ -167,6 +169,9 @@ def handle_plan_monitor_from_ob(cluster_name): # 输出表结构的信息 self.stdio.verbose("[sql plan monitor report task] report table schema") self.report_schema(user_sql, tenant_name) + # ASH 统计 + self.stdio.verbose("[ash report task] report ash, sql: [{0}]".format(sql_ash_top_event)) + self.report_ash_obversion4(sql_ash_top_event) self.init_monitor_stat() # 输出sql_audit的详细信息 self.stdio.verbose("[sql plan monitor report task] report sql_audit details") @@ -174,6 +179,9 @@ def handle_plan_monitor_from_ob(cluster_name): # 输出算子信息 表+图 self.stdio.verbose("[sql plan monitor report task] report sql plan monitor dfo") self.report_sql_plan_monitor_dfo_op(sql_plan_monitor_dfo_op) + # db time + self.stdio.verbose("[db time display task] report db time display") + self.report_db_time_display_op(sql_plan_monitor_db_time) # 输出算子信息按 svr 级汇总 表+图 self.stdio.verbose("[sql plan monitor report task] report sql plan monitor group by server") self.report_sql_plan_monitor_svr_agg(sql_plan_monitor_svr_agg_v1, sql_plan_monitor_svr_agg_v2) @@ -324,7 +332,10 @@ def report_pre(self, s): self.__report(pre) def report_header(self): - header = GlobalHtmlMeta().get_value(key="sql_plan_monitor_report_header") + if self.ob_major_version >= 4: + header = GlobalHtmlMeta().get_value(key="sql_plan_monitor_report_header_obversion4") + else: + header = GlobalHtmlMeta().get_value(key="sql_plan_monitor_report_header") with open(self.report_file_path, 'w') as f: f.write(header) self.stdio.verbose("report header complete") @@ -627,6 +638,7 @@ def report_svr_agg_graph_data_obversion4(self, ident, cursor, title=''): def report_fast_preview(self): content = ''' + + + + + + +

SQL Monitor Report

+ + ''', +) + html_dict.set_value( "sql_plan_monitor_report_footer", ''' diff --git a/handler/meta/sql_meta.py b/handler/meta/sql_meta.py index 1cdd61af..b4053f73 100644 --- a/handler/meta/sql_meta.py +++ b/handler/meta/sql_meta.py @@ -892,7 +892,7 @@ def rm_value(self, key): TRUNCATE(AVG(DB_TIME-USER_IO_WAIT_TIME)/1000000000.0/2.5, 2) MY_CPU_TIME, TRUNCATE(AVG(USER_IO_WAIT_TIME)/1000000000.0/2.5, 2) MY_IO_TIME FROM oceanbase.gv$sql_plan_monitor -WHERE trace_id = '##REPLACE_TRACE_ID##' +WHERE CON_ID = ##REPLACE_TENANT_ID## AND trace_id = '##REPLACE_TRACE_ID##' GROUP BY PLAN_LINE_ID, PLAN_OPERATION, PLAN_DEPTH ORDER BY PLAN_LINE_ID ''', @@ -1432,3 +1432,11 @@ def rm_value(self, key): SELECT tenant_name FROM oceanbase.DBA_OB_TENANTS where TENANT_TYPE != 'META'; ''', ) + +sql_dict.set_value( + "ash_top_event_mysql", + ''' + SELECT SQL_PLAN_LINE_ID OP_ID, IF(EVENT = '', 'CPU + WAIT FOR CPU', EVENT) AS EVENT, WAIT_CLASS, COUNT(1) EVENT_CNT, ROUND(COUNT(1) * 100 / SUM(COUNT(1)) OVER (), 2) AS Percent, MAX(P1TEXT) P1TEXT, MAX(P1) P1, MAX(P2TEXT) P2TEXT, MAX(P2) P2, MAX(P3TEXT) P3TEXT, MAX(P3) P3 + FROM OCEANBASE.GV$ACTIVE_SESSION_HISTORY A WHERE CON_ID = ##REPLACE_TENANT_ID## AND TRACE_ID = '##REPLACE_TRACE_ID##' GROUP BY A.SQL_PLAN_LINE_ID, A.EVENT, A.WAIT_CLASS ORDER BY 1 ASC, 4 DESC + ''', +)