Skip to content

Commit

Permalink
obdiag display support 3.x
Browse files Browse the repository at this point in the history
  • Loading branch information
jingyd66 committed Nov 11, 2024
1 parent 3c4e48b commit 2d3ed88
Show file tree
Hide file tree
Showing 13 changed files with 371 additions and 13 deletions.
4 changes: 4 additions & 0 deletions handler/display/step/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ def execute(self):
table = PrettyTable(columns)
for row in data:
table.add_row(row)
title = self.step.get("tittle")
if title is not None:
formatted_title = f"\n[obdiag display]: {title} "
self.stdio.print(formatted_title)
self.stdio.print(table)
except Exception as e:
self.stdio.error("StepSQLHandler execute Exception: {0}".format(e).strip())
Expand Down
48 changes: 48 additions & 0 deletions handler/display/tasks/observer/cluster_info.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,51 @@ 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, *]"
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
union all
(select /*+ READ_CONSISTENCY(WEAK) query_timeout(100000000)*/ \"cluster_id\" stat_name, cluster_id value from oceanbase.v$ob_cluster limit 1)
union all
(select /*+ READ_CONSISTENCY(WEAK) query_timeout(100000000)*/ \"version\" stat_name, build_version value from oceanbase.__all_server limit 1)
union all
select /*+ READ_CONSISTENCY(WEAK) query_timeout(100000000)*/ \"observers\" stat_name, count(*) value from oceanbase.__all_server
union all
select /*+ READ_CONSISTENCY(WEAK) query_timeout(100000000)*/ \"zones\" stat_name, count(distinct zone) value from oceanbase.__all_server
union all
select /*+ READ_CONSISTENCY(WEAK) query_timeout(100000000)*/ \"tenants\" stat_name, count(*) value from oceanbase.__all_tenant
union all
select /*+ READ_CONSISTENCY(WEAK) query_timeout(100000000)*/ \"rs_list\" stat_name, value from oceanbase.__all_sys_parameter where name ='rootservice_list'
union all
select /*+ READ_CONSISTENCY(WEAK) query_timeout(100000000)*/ \"config_url\" stat_name, value from oceanbase.__all_sys_parameter where name ='obconfig_url'
union all
select /*+ READ_CONSISTENCY(WEAK) query_timeout(100000000)*/ \"memory_limit\" stat_name, concat(sum(round((memory_limit+value)/1024/1024/1024,2)),'G') value from (select concat(round(a.mem_capacity/1024/1024/1024,2),'G')
mem_capacity,a.mem_capacity memory_limit,
case when right(b.value,1)='G' then substring(b.value,1,position('G' in b.value)-1)*1024*1024*1024
when right(b.value,1)='M' then substring(b.value,1,position('G' in b.value)-1)*1024*1024
end as value,a.svr_ip
from oceanbase.__all_virtual_server_stat a
inner join oceanbase.__all_virtual_sys_parameter_stat b on a.svr_ip=b.svr_ip and b.name='system_memory')
union all
select /*+ READ_CONSISTENCY(WEAK) query_timeout(100000000)*/ \"data_disk_allocated\" stat_name, concat(sum(TRUNCATE(disk_assigned/1024/1024/1024,0)),'G') value from oceanbase.__all_virtual_server_stat
union all
select /*+ READ_CONSISTENCY(WEAK) query_timeout(100000000)*/ \"cpu_total\" stat_name, sum(cpu_capacity) value from oceanbase.__all_virtual_server_stat
union all
select /*+ READ_CONSISTENCY(WEAK) query_timeout(100000000)*/ \"cpu_assigned\" stat_name, sum(cpu_assigned) value from oceanbase.__all_virtual_server_stat
union all
select /*+ READ_CONSISTENCY(WEAK) query_timeout(100000000)*/ \"cpu_assinged_per\" stat_name, concat(round(sum(cpu_assigned)/sum(cpu_capacity), 2)*100, '%') value from oceanbase.__all_virtual_server_stat
union all
select /*+ READ_CONSISTENCY(WEAK) query_timeout(100000000)*/ \"memory_total\" stat_name, concat(sum(TRUNCATE(mem_total/1024/1024/1024,0)),'G') value from oceanbase.__all_virtual_server_stat
union all
select /*+ READ_CONSISTENCY(WEAK) query_timeout(100000000)*/ \"memory_assigned\" stat_name, concat(sum(TRUNCATE(mem_assigned/1024/1024/1024,0)),'G') value from oceanbase.__all_virtual_server_stat
union all
select /*+ READ_CONSISTENCY(WEAK) query_timeout(100000000)*/ \"memory_assigned_per\" stat_name, concat(round(sum(mem_assigned/1024/1024/1024)/sum(mem_capacity/1024/1024/1024), 2)*100, '%') value from oceanbase.__all_virtual_server_stat
union all
select /*+ READ_CONSISTENCY(WEAK) query_timeout(100000000)*/ \"data_disk_total\" stat_name, concat(sum(TRUNCATE(disk_total/1024/1024/1024,0)),'G') value from oceanbase.__all_virtual_server_stat
union all
select /*+ READ_CONSISTENCY(WEAK) query_timeout(100000000)*/ \"data_disk_in_use\" stat_name, concat(sum(TRUNCATE(disk_in_use/1024/1024/1024,0)),'G') value from oceanbase.__all_virtual_server_stat
union all
select /*+ READ_CONSISTENCY(WEAK) query_timeout(100000000)*/ \"data_disk_in_use_per\" stat_name, concat(round(sum(disk_in_use/1024/1024/1024)/sum(disk_total/1024/1024/1024), 2)*100, '%') value from oceanbase.__all_virtual_server_stat;"
global: true

33 changes: 33 additions & 0 deletions handler/display/tasks/observer/database_datasize.yml
Original file line number Diff line number Diff line change
@@ -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, *]"
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
__all_virtual_meta_table a inner join
(select a.* from
gv$table a
inner join
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

52 changes: 47 additions & 5 deletions handler/display/tasks/observer/event.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
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 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, *]"
steps:
- type: sql
sql: "SELECT
sql: "select b.tenant_name,a.* from (SELECT
/* MONITOR_AGENT */
con_id tenant_id,
CASE
Expand All @@ -27,9 +28,9 @@ task:
SUM(total_waits) AS total_waits,
SUM(time_waited_micro / 1000000) AS time_waited
FROM
oceanbase.v$system_event
oceanbase.gv$system_event
WHERE
oceanbase.v$system_event.wait_class <> 'IDLE'
oceanbase.gv$system_event.wait_class <> 'IDLE'
AND (
con_id > 1000
OR con_id = 1
Expand All @@ -39,5 +40,46 @@ task:
event_group
ORDER BY
tenant_id,
event_group;"
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, *]"
steps:
- type: sql
sql: "select b.tenant_name,a.* from (SELECT
/* MONITOR_AGENT */
con_id tenant_id,
CASE
WHEN event_id = 10000 THEN 'INTERNAL'
WHEN event_id = 13000 THEN 'SYNC_RPC'
WHEN event_id = 14003 THEN 'ROW_LOCK_WAIT'
WHEN (
event_id >= 10001
AND event_id <= 11006
)
OR (
event_id >= 11008
AND event_id <= 11011
) THEN 'IO'
WHEN event LIKE 'latch:%' THEN 'LATCH'
ELSE 'OTHER'
END
event_group,
SUM(total_waits) AS total_waits,
SUM(time_waited_micro / 1000000) AS time_waited
FROM
oceanbase.gv$system_event
WHERE
oceanbase.gv$system_event.wait_class <> 'IDLE'
AND (
con_id > 1000
OR con_id = 1
)
GROUP BY
tenant_id,
event_group
ORDER BY
tenant_id,
event_group) a, oceanbase.__all_tenant b
where a.tenant_id=b.tenant_id and b.tenant_name='{tenant_name}';"
global: true
14 changes: 11 additions & 3 deletions handler/display/tasks/observer/plan.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
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 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}';"
global: true
#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}';"
global: true
- version: "[3.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}';"
global: true
11 changes: 9 additions & 2 deletions handler/display/tasks/observer/processlist.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
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 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, *]"
steps:
- type: sql
sql: "select * from oceanbase.gv$ob_processlist;"
sql: "select * from oceanbase.gv$ob_processlist where tenant='{tenant_name}';"
global: true
- version: "[3.0.0.0, *]"
steps:
- type: sql
sql: "select * from oceanbase.__all_virtual_processlist where tenant='{tenant_name}';"
global: true

8 changes: 8 additions & 0 deletions handler/display/tasks/observer/rs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ info_cn: "[查看rootservice信息]"
command: obdiag display scene run --scene=observer.rs
task:
- version: "[4.0.0.0, *]"
steps:
- type: sql
sql: "show parameters like '%rootservice_list%';"
global: true
- type: sql
sql: "select * from oceanbase.__all_rootservice_event_history order by 1 desc limit 10;"
global: true
- version: "[3.0.0.0, *]"
steps:
- type: sql
sql: "show parameters like '%rootservice_list%';"
Expand Down
7 changes: 6 additions & 1 deletion handler/display/tasks/observer/server_info.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@ task:
- version: "[4.0.0.0, *]"
steps:
- type: sql
sql: "select * from oceanbase.__all_server;"
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, *]"
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;"
global: true
41 changes: 39 additions & 2 deletions handler/display/tasks/observer/slowsql.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
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 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:
- version: "[4.0.0.0, *]"
steps:
Expand Down Expand Up @@ -28,10 +30,45 @@ task:
FROM
oceanbase.gv$ob_sql_audit
WHERE
1 = 1
tenant_name='{tenant_name}'
AND 1 = 1
AND request_time > (time_to_usec(now()) - {mtime} * 60 * 1000000)
AND is_inner_sql = 0
ORDER BY
elapsed_time DESC
LIMIT 10;"
global: true
- version: "[3.0.0.0, *]"
steps:
- type: sql
sql: "SELECT
/*+READ_CONSISTENCY(WEAK), QUERY_TIMEOUT(100000000)*/
tenant_id,
tenant_name,
user_name,
db_name,
svr_ip,
plan_id,
plan_type,
affected_rows,
return_rows,
elapsed_time,
execute_time,
sql_id,
usec_to_time(request_time),
substr(
replace(query_sql, '\n', ' '),
1,
100
)
FROM
oceanbase.gv$sql_audit
WHERE
tenant_name='{tenant_name}'
AND 1 = 1
AND request_time > (time_to_usec(now()) - {mtime} * 60 * 1000000)
AND is_inner_sql = 0
ORDER BY
elapsed_time DESC
LIMIT 10;"
global: true
43 changes: 43 additions & 0 deletions handler/display/tasks/observer/table_datasize.yml
Original file line number Diff line number Diff line change
@@ -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, *]"
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
__all_virtual_meta_table a
JOIN
(select a.* from
gv$table a
inner join
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


Loading

0 comments on commit 2d3ed88

Please sign in to comment.