From e3592a2920ca60e763d3050963a3ab24c26419db Mon Sep 17 00:00:00 2001 From: jingyd66 <1071948456@qq.com> Date: Wed, 13 Nov 2024 15:40:41 +0800 Subject: [PATCH] update1113 --- handler/display/step/sql.py | 1 + .../display/tasks/observer/cluster_info.yaml | 2 +- .../tasks/observer/database_datasize.yaml | 33 ++++++++++++++ handler/display/tasks/observer/event.yaml | 3 +- handler/display/tasks/observer/plan.yaml | 6 +-- .../display/tasks/observer/processlist.yaml | 3 +- handler/display/tasks/observer/rs.yaml | 2 +- .../display/tasks/observer/server_info.yaml | 2 +- handler/display/tasks/observer/slowsql.yaml | 3 +- .../tasks/observer/table_datasize.yaml | 43 +++++++++++++++++++ .../display/tasks/observer/tenant_info.yaml | 2 +- handler/display/tasks/observer/topsql.yaml | 25 +++-------- handler/display/tasks/observer/unit_info.yaml | 2 +- handler/display/tasks/observer/zone_info.yaml | 2 +- 14 files changed, 93 insertions(+), 36 deletions(-) create mode 100644 handler/display/tasks/observer/database_datasize.yaml create mode 100644 handler/display/tasks/observer/table_datasize.yaml diff --git a/handler/display/step/sql.py b/handler/display/step/sql.py index 11bb0103..a4907de7 100644 --- a/handler/display/step/sql.py +++ b/handler/display/step/sql.py @@ -65,6 +65,7 @@ def execute(self): table.add_row(row) title = self.step.get("tittle") if title is not None: + title = StringUtils.replace_parameters(formatted_title, self.env) formatted_title = f"\n[obdiag display]: {title} " self.stdio.print(formatted_title) self.stdio.print(table) diff --git a/handler/display/tasks/observer/cluster_info.yaml b/handler/display/tasks/observer/cluster_info.yaml index e23c06fa..ac1ec7df 100644 --- a/handler/display/tasks/observer/cluster_info.yaml +++ b/handler/display/tasks/observer/cluster_info.yaml @@ -53,7 +53,7 @@ task: union all select /*+ READ_CONSISTENCY(WEAK) query_timeout(100000000)*/ \"data_disk_in_use_per\" stat_name, concat(round(sum(data_disk_in_use/1024/1024/1024)/sum(data_disk_capacity/1024/1024/1024), 2)*100, '%') value from oceanbase.gv$ob_servers;" global: true - - version: "[3.0.0.0, *]" + - version: "[3.0.0.0, 4.0.0.0]" steps: - type: sql sql: "select /*+ READ_CONSISTENCY(WEAK) query_timeout(100000000)*/ \"cluster_name\" stat_name, cluster_name value from oceanbase.v$ob_cluster limit 1 diff --git a/handler/display/tasks/observer/database_datasize.yaml b/handler/display/tasks/observer/database_datasize.yaml new file mode 100644 index 00000000..64121ec4 --- /dev/null +++ b/handler/display/tasks/observer/database_datasize.yaml @@ -0,0 +1,33 @@ +info_en: "[database data_size]" +info_cn: "[查看库占用磁盘大小]" +command: obdiag display scene run --scene=observer.database_datasize --env tenant_id=1006 --env database_name=test +task: + - version: "[4.0.0.0, *]" + steps: + - type: sql + sql: "select tenant_id,tenant_name,DATABASE_NAME,sum(data_size_in_GB) as data_size_in_GB from + (SELECT /*+ query_timeout(30000000) */ a.TENANT_ID, c.tenant_name, a.DATABASE_NAME, a.TABLE_NAME, a.TABLE_ID, + SUM(CASE WHEN b.nested_offset = 0 THEN IFNULL(b.data_block_count + b.index_block_count + b.linked_block_count, 0) * 2 * 1024 * 1024 ELSE IFNULL(b.size, 0) END ) /1024.0 /1024/1024 AS data_size_in_GB + FROM oceanbase.CDB_OB_TABLE_LOCATIONS a INNER JOIN oceanbase.__all_virtual_table_mgr b ON a.svr_ip = b.svr_ip + AND a.svr_port = b.svr_port AND a.tenant_id = b.tenant_id AND a.LS_ID = b.LS_ID AND a.TABLET_ID = b.TABLET_ID + inner join oceanbase.__all_tenant c on a.tenant_id=c.tenant_id WHERE a.role = 'LEADER' + AND c.tenant_id = {tenant_id} AND b.table_type >= 10 AND b.size > 0 AND a.TABLE_NAME NOT REGEXP '^__' + and a.database_name='{database_name}' GROUP BY a.TABLE_ID) group by database_name;" + global: true + - version: "[3.0.0.0, 4.0.0.0]" + steps: + - type: sql + sql: "select a.tenant_id, b.database_name,SUM(a.data_size) / 1024 / 1024 / 1024 AS data_size_G, + SUM(a.required_size) / 1024 / 1024 / 1024 AS required_size_G from + oceanbase.__all_virtual_meta_table a inner join + (select a.* from + oceanbase.gv$table a + inner join + oceanbase.gv$database b + on a.database_id=b.database_id + where b.tenant_id={tenant_id} and b.database_name='{database_name}')b + on a.table_id=b.table_id + where a.role = 1 + group by a.tenant_id, b.database_name;" + global: true + diff --git a/handler/display/tasks/observer/event.yaml b/handler/display/tasks/observer/event.yaml index 219bda3d..ddf91417 100644 --- a/handler/display/tasks/observer/event.yaml +++ b/handler/display/tasks/observer/event.yaml @@ -1,6 +1,5 @@ info_en: "[event]" info_cn: "[event信息]" -# command: obdiag display scene run --scene=observer.event --env db_connect='-h127.0.0.1 -P2881 -utest@test -p****** -Dtest' command: obdiag display scene run --scene=observer.event --env tenant_name=test task: - version: "[4.0.0.0, *]" @@ -43,7 +42,7 @@ task: event_group) a, oceanbase.__all_tenant b where a.tenant_id=b.tenant_id and b.tenant_name='{tenant_name}';" global: true - - version: "[3.0.0.0, *]" + - version: "[3.0.0.0, 4.0.0.0]" steps: - type: sql sql: "select b.tenant_name,a.* from (SELECT diff --git a/handler/display/tasks/observer/plan.yaml b/handler/display/tasks/observer/plan.yaml index 18dd7bb6..83df3ec9 100644 --- a/handler/display/tasks/observer/plan.yaml +++ b/handler/display/tasks/observer/plan.yaml @@ -1,16 +1,14 @@ info_en: "[plan]" info_cn: "[查看sql的执行计划]" -# command: obdiag display scene run --scene=observer.plan --env db_connect='-h127.0.0.1 -P2881 -utest@test -p****** -Dtest' --env sqlid=test command: obdiag display scene run --scene=observer.plan --env tenant_name=test --env sqlid=test task: - version: "[4.0.0.0, *]" steps: - type: sql - #sql: "SELECT * FROM oceanbase.V$OB_PLAN_CACHE_PLAN_STAT where sql_id = '{sqlid}';" - sql: "SELECT a.* FROM oceanbase.V$OB_PLAN_CACHE_PLAN_STAT a left join oceanbase.__all_tenant b on a.tenant_id=b.tenant_id where b.tenant_name='{tenant_name}' and a.sql_id = '{sqlid}';" + sql: "SELECT a.* FROM oceanbase.GV$OB_PLAN_CACHE_PLAN_STAT a left join oceanbase.__all_tenant b on a.tenant_id=b.tenant_id where b.tenant_name='{tenant_name}' and a.sql_id = '{sqlid}';" global: true - - version: "[3.0.0.0, *]" + - version: "[3.0.0.0, 4.0.0.0]" steps: - type: sql sql: "SELECT a.* FROM oceanbase.GV$plan_cache_plan_stat a left join oceanbase.__all_tenant b on a.tenant_id=b.tenant_id where b.tenant_name='{tenant_name}' and a.sql_id = '{sqlid}';" diff --git a/handler/display/tasks/observer/processlist.yaml b/handler/display/tasks/observer/processlist.yaml index e4bb7d8f..acea5951 100644 --- a/handler/display/tasks/observer/processlist.yaml +++ b/handler/display/tasks/observer/processlist.yaml @@ -1,6 +1,5 @@ info_en: "[processlist]" info_cn: "[查看processlist]" -# command: obdiag display scene run --scene=observer.processlist --env db_connect='-h127.0.0.1 -P2881 -utest@test -p****** -Dtest' command: obdiag display scene run --scene=observer.processlist --env tenant_name=test task: - version: "[4.0.0.0, *]" @@ -8,7 +7,7 @@ task: - type: sql sql: "select * from oceanbase.gv$ob_processlist where tenant='{tenant_name}';" global: true - - version: "[3.0.0.0, *]" + - version: "[3.0.0.0, 4.0.0.0]" steps: - type: sql sql: "select * from oceanbase.__all_virtual_processlist where tenant='{tenant_name}';" diff --git a/handler/display/tasks/observer/rs.yaml b/handler/display/tasks/observer/rs.yaml index ce396f52..2b3a3fa7 100644 --- a/handler/display/tasks/observer/rs.yaml +++ b/handler/display/tasks/observer/rs.yaml @@ -10,7 +10,7 @@ task: - type: sql sql: "select * from oceanbase.__all_rootservice_event_history order by 1 desc limit 10;" global: true - - version: "[3.0.0.0, *]" + - version: "[3.0.0.0, 4.0.0.0]" steps: - type: sql sql: "show parameters like '%rootservice_list%';" diff --git a/handler/display/tasks/observer/server_info.yaml b/handler/display/tasks/observer/server_info.yaml index 83c432ad..2dc13107 100644 --- a/handler/display/tasks/observer/server_info.yaml +++ b/handler/display/tasks/observer/server_info.yaml @@ -7,7 +7,7 @@ task: - type: sql sql: "SELECT /*+READ_CONSISTENCY(WEAK), QUERY_TIMEOUT(100000000)*/ zone, svr_ip, with_rootserver rs, case when start_service_time = 0 then NULL else CAST(usec_to_time(start_service_time) AS DATETIME) end start_service_time, case when stop_time = 0 then NULL else CAST(usec_to_time(stop_time) AS DATETIME) end stop_time, case when last_offline_time = 0 then NULL else CAST(usec_to_time(last_offline_time) AS DATETIME) end last_offline_time, status, SUBSTR(build_version, 1, INSTR(build_version, '-') - 1) build_version FROM oceanbase.__all_server order by zone, svr_ip;" global: true - - version: "[3.0.0.0, *]" + - version: "[3.0.0.0, 4.0.0.0]" steps: - type: sql sql: "SELECT /*+READ_CONSISTENCY(WEAK), QUERY_TIMEOUT(100000000)*/ zone, svr_ip, with_rootserver rs, case when start_service_time = 0 then NULL else CAST(usec_to_time(start_service_time) AS DATETIME) end start_service_time, case when stop_time = 0 then NULL else CAST(usec_to_time(stop_time) AS DATETIME) end stop_time, case when last_offline_time = 0 then NULL else CAST(usec_to_time(last_offline_time) AS DATETIME) end last_offline_time, status, SUBSTR(build_version, 1, INSTR(build_version, '-') - 1) build_version FROM oceanbase.__all_server order by zone, svr_ip;" diff --git a/handler/display/tasks/observer/slowsql.yaml b/handler/display/tasks/observer/slowsql.yaml index 213bed73..0f77c012 100644 --- a/handler/display/tasks/observer/slowsql.yaml +++ b/handler/display/tasks/observer/slowsql.yaml @@ -1,6 +1,5 @@ info_en: "[slowsql]" info_cn: "[查看慢sql]" -# command: obdiag display scene run --scene=observer.slowsql --env db_connect='-h127.0.0.1 -P2881 -utest@test -p****** -Dtest' --env mtime=10 command: obdiag display scene run --scene=observer.slowsql --env tenant_name=test --env mtime=10 task: @@ -38,7 +37,7 @@ task: elapsed_time DESC LIMIT 10;" global: true - - version: "[3.0.0.0, *]" + - version: "[3.0.0.0, 4.0.0.0]" steps: - type: sql sql: "SELECT diff --git a/handler/display/tasks/observer/table_datasize.yaml b/handler/display/tasks/observer/table_datasize.yaml new file mode 100644 index 00000000..baaa5e66 --- /dev/null +++ b/handler/display/tasks/observer/table_datasize.yaml @@ -0,0 +1,43 @@ +info_en: "[table data_size]" +info_cn: "[查看表占用磁盘大小]" +command: obdiag display scene run --scene=observer.table_datasize --env tenant_id=1006 --env database_name=test --env table_name=ttt2 +task: + - version: "[4.0.0.0, *]" + steps: + - type: sql + sql: "SELECT /*+ query_timeout(30000000) */ a.TENANT_ID, c.tenant_name, a.DATABASE_NAME, a.TABLE_NAME, a.TABLE_ID, + SUM(CASE WHEN b.nested_offset = 0 THEN IFNULL(b.data_block_count + b.index_block_count + b.linked_block_count, 0) * 2 * 1024 * 1024 ELSE IFNULL(b.size, 0) END ) / 1024.0 / 1024 / 1024 AS data_size_in_GB + FROM oceanbase.CDB_OB_TABLE_LOCATIONS a INNER JOIN oceanbase.__all_virtual_table_mgr b ON a.svr_ip = b.svr_ip AND a.svr_port = b.svr_port AND a.tenant_id = b.tenant_id AND a.LS_ID = b.LS_ID AND a.TABLET_ID = b.TABLET_ID + inner join oceanbase.__all_tenant c on a.tenant_id=c.tenant_id + WHERE a.role = 'LEADER' AND c.tenant_id = {tenant_id} + AND b.table_type >= 10 AND b.size > 0 + AND a.TABLE_NAME NOT REGEXP '^__' + and a.database_name='{database_name}' + and a.TABLE_NAME='{table_name}' GROUP BY a.TABLE_ID;" + global: true + + - version: "[3.0.0.0, 4.0.0.0]" + steps: + - type: sql + sql: "SELECT + a.tenant_id, + b.table_name, + SUM(a.data_size) / 1024 / 1024 / 1024 AS data_size_G, + SUM(a.required_size) / 1024 / 1024 / 1024 AS required_size_G + FROM + oceanbase.__all_virtual_meta_table a + JOIN + (select a.* from + oceanbase.gv$table a + inner join + oceanbase.gv$database b + on a.database_id=b.database_id + where b.tenant_id={tenant_id} and b.database_name='{database_name}' and a.table_name='{table_name}') b + ON + a.table_id = b.table_id + WHERE + a.role = 1 + group by a.tenant_id, b.table_name;" + global: true + + diff --git a/handler/display/tasks/observer/tenant_info.yaml b/handler/display/tasks/observer/tenant_info.yaml index e0a3f081..a9c9c5c9 100644 --- a/handler/display/tasks/observer/tenant_info.yaml +++ b/handler/display/tasks/observer/tenant_info.yaml @@ -10,7 +10,7 @@ task: - type: sql sql: "select /*+ READ_CONSISTENCY(WEAK) query_timeout(100000000)*/ dot.tenant_name, dou.zone, dou.svr_ip observer, cotl.replica_type, dou.max_cpu cpu, concat(round(dou.memory_size/1024/1024/1024,0), 'G') memory_size, concat(round(dou.log_disk_size/1024/1024/1024,0), 'G') log_disk_size, concat(round(sum(cotr.data_size)/1024/1024/1024, 2), 'G') data_size, concat(round(sum(cotr.required_size)/1024/1024/1024, 2), 'G') required_size, dot.unit_num from oceanbase.dba_ob_tenants dot, oceanbase.dba_ob_units dou, oceanbase.cdb_ob_table_locations cotl, oceanbase.cdb_ob_tablet_replicas cotr where tenant_name = '{tenant_name}' and dot.tenant_id = dou.tenant_id and dot.tenant_id = cotl.tenant_id and dou.svr_ip = cotl.svr_ip and cotl.tenant_id = cotr.tenant_id and cotl.svr_ip = cotr.svr_ip and cotl.ls_id = cotr.ls_id and cotl.tablet_id = cotr.tablet_id group by dot.tenant_id, cotl.svr_ip order by dot.tenant_id, zone, cotl.svr_ip;" global: true - - version: "[3.0.0.0, *]" + - version: "[3.0.0.0, 4.0.0.0]" steps: - type: sql sql: "select /*+ READ_CONSISTENCY(WEAK) query_timeout(100000000)*/ \"tenant_name\" stat_name, tenant_name value from oceanbase.__all_tenant where tenant_name='{tenant_name}' diff --git a/handler/display/tasks/observer/topsql.yaml b/handler/display/tasks/observer/topsql.yaml index e850df6c..3c96c8cd 100644 --- a/handler/display/tasks/observer/topsql.yaml +++ b/handler/display/tasks/observer/topsql.yaml @@ -1,29 +1,14 @@ info_en: "[topsql info]" info_cn: "[查看topsql]" -# command: obdiag display scene run --scene=observer.topsql --env db_connect='-h127.0.0.1 -P2881 -utest@test -p****** -Dtest' --env mtime=10 -command: obdiag display scene run --scene=observer.tenant_info --env tenant_name=test --env mtime=10 +command: obdiag display scene run --scene=observer.topsql --env tenant_name=test --env mtime=10 task: - # - version: "[4.0.0.0, *]" - # steps: - # - type: sql - # sql: "select tenant_name, SQL_ID, count(*) as QPS, avg(t1.ELAPSED_TIME) as ELAPSED_TIME_AVG, substr(query_sql,1,50) - # from oceanbase.gv$ob_sql_audit t1 - # where - # IS_EXECUTOR_RPC = 0 - # and request_time > (time_to_usec(now()) - {mtime} * 60 * 1000000) - # and request_time < time_to_usec(now()) - # and length(query_sql) > 0 - # and IS_INNER_SQL = 0 - # and length(sql_id) > 0 - # group by t1.sql_id order by QPS desc limit 10;" - # global: true - version: "[4.0.0.0, *]" steps: - type: sql tittle: Top SQL time consumption in the last {mtime} minutes sql: "select /*+read_consistency(weak),query_timeout(100000000)*/ tenant_name,SQL_ID,QUERY_SQL,count(1),avg(ELAPSED_TIME),avg(EXECUTE_TIME),avg(QUEUE_TIME),avg(AFFECTED_ROWS),avg(GET_PLAN_TIME) - from gv$ob_sql_audit + from oceanbase.gv$ob_sql_audit where time_to_usec(now(6))-request_time <{mtime}*60*1000000 and tenant_name='{tenant_name}' group by SQL_ID order by avg(ELAPSED_TIME)*count(1) desc limit 20;" @@ -50,7 +35,7 @@ task: global: true - type: sql tittle: Check whether there have been a large number of unreasonable remote execution requests for SQL executions in the past {mtime} minutes - sql: "select/ *+read_consistency(weak),query_timeout(100000000)*/ count(*), plan_type + sql: "select / *+read_consistency(weak),query_timeout(100000000)*/ count(*), plan_type from oceanbase.gv$ob_sql_audit where tenant_name ='{tenant_name}' and IS_EXECUTOR_RPC = 0 @@ -67,12 +52,12 @@ task: and request_time < time_to_usec(now()) group by sql_id limit 20;" global: true - - version: "[3.0.0.0, *]" + - version: "[3.0.0.0, 4.0.0.0]" steps: - type: sql tittle: Top SQL time consumption in the last {mtime} minutes sql: "select /*+read_consistency(weak),query_timeout(100000000)*/ tenant_name,SQL_ID,QUERY_SQL,count(1),avg(ELAPSED_TIME),avg(EXECUTE_TIME),avg(QUEUE_TIME),avg(AFFECTED_ROWS),avg(GET_PLAN_TIME) - from gv$sql_audit + from oceanbase.gv$sql_audit where time_to_usec(now(6))-request_time <{mtime}*60*1000000 and tenant_name='{tenant_name}' group by SQL_ID order by avg(ELAPSED_TIME)*count(1) desc limit 20 ;" diff --git a/handler/display/tasks/observer/unit_info.yaml b/handler/display/tasks/observer/unit_info.yaml index 1db17166..e6accc37 100644 --- a/handler/display/tasks/observer/unit_info.yaml +++ b/handler/display/tasks/observer/unit_info.yaml @@ -46,7 +46,7 @@ task: svr_port, unit_id;" global: true - - version: "[3.0.0.0, *]" + - version: "[3.0.0.0, 4.0.0.0]" steps: - type: sql sql: "SELECT diff --git a/handler/display/tasks/observer/zone_info.yaml b/handler/display/tasks/observer/zone_info.yaml index aadc809c..75f55130 100644 --- a/handler/display/tasks/observer/zone_info.yaml +++ b/handler/display/tasks/observer/zone_info.yaml @@ -7,7 +7,7 @@ task: - type: sql sql: "select * from oceanbase.dba_ob_zones;" global: true - - version: "[3.0.0.0, *]" + - version: "[3.0.0.0, 4.0.0.0]" steps: - type: sql sql: "select * from oceanbase.__all_zone;"