---
title: "一键场景化信息收集 - 敏捷诊断工具 V2.0.0 | OceanBase 文档中心"
description: 一键场景化信息收集 本文适用于独立部署 obdiag 的场景，使用 obdiag gather 命令可帮助 OceanBase 数据库相关的诊断信息收集。gather scenes 命令可以一键执行将某些问题场景所需要的排查信息统一捞回，解决分布式节点信息捞取难的痛点 前提条件 说明 需要确保已经在 obdiag 配…
---
切换语言

- 中文站 - 简体中文
- International - English
- 日本站 - 日本語

文档反馈![](https://mdn.alipayobjects.com/huamei_22khvb/afts/img/A*5ZXST55u540AAAAAAAAAAAAADiGDAQ/original) 敏捷诊断工具V 2.0.0

# 一键场景化信息收集

更新时间：2024-04-19 14:56:16

[编辑](https://github.com/oceanbase/odt-doc/edit/V2.0.0/zh-CN/400.gather/410.obdiag-gather-scene-guide.md)  

本文适用于独立部署 obdiag 的场景，使用 obdiag gather 命令可帮助 OceanBase 数据库相关的诊断信息收集。gather scenes 命令可以一键执行将某些问题场景所需要的排查信息统一捞回，解决分布式节点信息捞取难的痛点

## 前提条件

#### 说明

需要确保已经在 obdiag 配置文件 `config.yml` 中配置好需要收集节点的登录信息。相关的详细配置介绍，参见 [obdiag 配置](https://www.oceanbase.com/docs/common-obdiag-cn-1000000000691942)。

## 查看当前支持的场景

```shell
obdiag gather scene list

```

```bash
obdiag gather scene list

[Other Problem Gather Scenes]:
---------------------------------------------------------------------------------------
command                                                   info_en               info_cn
---------------------------------------------------------------------------------------
obdiag gather scene run --scene=other.application_error   [application error]   [应用报错问题]
---------------------------------------------------------------------------------------

[Obproxy Problem Gather Scenes]:
----------------------------------------------------------------------------------
command                                           info_en             info_cn
----------------------------------------------------------------------------------
obdiag gather scene run --scene=obproxy.restart   [obproxy restart]   [obproxy无故重启]
----------------------------------------------------------------------------------

[Observer Problem Gather Scenes]:
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
command                                                                                                                                   info_en                                       info_cn
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
obdiag gather scene run --scene=observer.backup                                                                                           [backup problem]                              [数据备份问题]
obdiag gather scene run --scene=observer.backup_clean                                                                                     [backup clean]                                [备份清理问题]
obdiag gather scene run --scene=observer.clog_disk_full                                                                                   [clog disk full]                              [clog盘满]
obdiag gather scene run --scene=observer.cluster_down                                                                                     [cluster down]                                [集群无法连接]
obdiag gather scene run --scene=observer.compaction                                                                                       [compaction]                                  [合并问题]
obdiag gather scene run --scene=observer.cpu_high                                                                                         [High CPU]                                    [CPU高]
obdiag gather scene run --scene=observer.delay_of_primary_and_backup                                                                      [delay of primary and backup]                 [主备库延迟]
obdiag gather scene run --scene=observer.io                                                                                               [io problem]                                  [io问题]
obdiag gather scene run --scene=observer.log_archive                                                                                      [log archive]                                 [日志归档问题]
obdiag gather scene run --scene=observer.long_transaction                                                                                 [long transaction]                            [长事务]
obdiag gather scene run --scene=observer.memory                                                                                           [memory problem]                              [内存问题]
obdiag gather scene run --scene=observer.perf_sql --env "{db_connect='-h127.0.0.1 -P2881 -utest@test -p****** -Dtest', trace_id='Yxx'}"   [SQL performance problem]                     [SQL性能问题]
obdiag gather scene run --scene=observer.px_collect_log --env "{trace_id='Yxx', estimated_time='2024-04-19 14:46:17'}"                    [Collect error source node logs for SQL PX]   [SQL PX 收集报错源节点日志]
obdiag gather scene run --scene=observer.recovery                                                                                         [recovery]                                    [数据恢复问题]
obdiag gather scene run --scene=observer.restart                                                                                          [restart]                                     [observer无故重启]
obdiag gather scene run --scene=observer.rootservice_switch                                                                               [rootservice switch]                          [有主改选或者无主选举的切主]
obdiag gather scene run --scene=observer.sql_err --env "{db_connect='-h127.0.0.1 -P2881 -utest@test -p****** -Dtest', trace_id='Yxx'}"    [SQL execution error]                         [SQL 执行出错]
obdiag gather scene run --scene=observer.suspend_transaction                                                                              [suspend transaction]                         [悬挂事务]
obdiag gather scene run --scene=observer.unit_data_imbalance                                                                              [unit data imbalance]                         [unit迁移/缩小 副本不均衡问题]
obdiag gather scene run --scene=observer.unknown                                                                                          [unknown problem]                             [未能明确问题的场景]
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

```

## obdiag gather scene run 使用

```shell
obdiag gather scene run --scene={SceneName}

```

### 试用说明

```shell
--scene={SceneName}

SceneName 是对需要执行收集的场景

Example1:
obdiag gather scene run --scene=observer.unknown

```

选项说明如下：

| 选项名 | 是否必选 | 数据类型 | 默认值 | 说明 |
| --- | --- | --- | --- | --- |
| --scene | 是 | string | 默认为空 | 场景名，可以通过obdiag gather scene list 查看当前版本支持哪些场景 |
| --from | 否 | string | 默认为空 | 日志收集的开始时间，格式为: `yyyy-mm-dd hh:mm:ss`。 |
| --to | 否 | string | 默认为空 | 日志收集的结束时间，格式为: `yyyy-mm-dd hh:mm:ss`。 |
| --since | 否 | string | 默认为空 | 日志收集最近的某段时间，格式为: `\<n> <m\\|h\\|d>`，其中，n 表示待输入的时间数字，m 表示分钟，h 表示小时，d 表示天，例如 `30m` 表示收集最近 30 分钟的日志。 |
| --env | 否 | string | 默认为空 | 部分场景需要额外的参数才能支持，统一放到了--env这个参数里边 |
| --store_dir | 否 | string | 默认为命令执行的当前路径 | 存储结果的本地路径。 |
| -c | 否 | string | `~/.obdiag/config.yml` | 配置文件路径 |

#### 说明

如果不特别指定存储目录 store_dir ，收集的结果会存放在当前目录下 gather_pack_xxxx 的文件夹中

### 指定场景的信息收集

```bash
# 应用报错问题
obdiag gather scene run --scene=other.application_error

# obproxy无故重启
obdiag gather scene run --scene=obproxy.restart

# 数据备份问题
obdiag gather scene run --scene=observer.backup

# 备份清理问题
obdiag gather scene run --scene=observer.backup_clean

# clog盘满
obdiag gather scene run --scene=observer.clog_disk_full

# 合并问题
obdiag gather scene run --scene=observer.compaction

# CPU高
obdiag gather scene run --scene=observer.cpu_high

# 主备库延迟
obdiag gather scene run --scene=observer.delay_of_primary_and_backup

# 日志归档问题
obdiag gather scene run --scene=observer.log_archive

# 长事务
obdiag gather scene run --scene=observer.long_transaction

# 内存问题
obdiag gather scene run --scene=observer.memory

# SQL性能问题, 此处env中的trace_id对应gv$ob_sql_audit的trace_id
obdiag gather scene run --scene=observer.perf_sql --env "{db_connect='-hxx -Pxx -uxx -pxx -Dxx', trace_id='xx'}"

# 数据恢复问题
obdiag gather scene run --scene=observer.recovery

# observer无故重启
obdiag gather scene run --scene=observer.restart  

# 有主改选或者无主选举的切主
obdiag gather scene run --scene=observer.rootservice_switch  

# SQL 执行出错， 此处env中的trace_id对应gv$ob_sql_audit的trace_id
obdiag gather scene run --scene=observer.sql_err --env "{db_connect='-hxx -Pxx -uxx -pxx -Dxx', trace_id='xx'}"

# 悬挂事务
obdiag gather scene run --scene=observer.suspend_transaction

# unit迁移/缩小 副本不均衡问题
obdiag gather scene run --scene=observer.unit_data_imbalance

# 未能明确问题的场景
obdiag gather scene run --scene=observer.unknown

# SQL PX 收集报错源节点日志，两个参数：trace_id：必填，会根据该trace_id去搜集px的日志， estimated_time：选填，默认为当前时间，会搜 这个时间点以前一周的日志
obdiag gather scene run --scene=observer.px_collect_log --env "{trace_id='Yxx', estimated_time='2024-04-19 14:46:17'}"

```

如果想想获取指定时间的信息，可以添加时间范围的参数，--from, --to 或者 --since 比如添加 --from --to 参数指定获取2024-01-30 12:30:00 到 2024-01-30 12:40:00 这10分钟的数据

```bash
obdiag gather scene run --scene=other.application_error --from 2024-01-30 12:30:00 --to 2024-01-30 12:40:00

```

再比如--since 参数获取最近10分钟的信息

```bash
obdiag gather scene run --scene=other.application_error --since 10m

```

## 自定义场景编写教程

一个task表示一个独立的场景，可以理解为一个专业的，用 yaml 编写的，用 obdiag 识别的脚本文件。

### 开始编写前

编写前需要确定yaml需要放在哪

可以先进入 /usr/local/oceanbase-diagnostic-tool/conf/inner_config.yml 文件中设置 gather.scenes_base_path 所标识的目录里，看下编写的采集场景是否属于已有的大类，若没有就创建一个文件夹用于声明这个大类

例：

```ssh
#先进入 ${gather.scenes_base_path} ,并创建我们的示例文件 test.yaml (以 observer 为测试目标)
cd ~/.obdiag/gather/tasks/observer
touch test.yaml

```

以上便完成了编写前的步骤

### 开始编写

开始编写就是开始编辑我们的 test.yaml

```yaml
# 首先需要声明下这个场景的作用，为了让大家看得懂

info: "for test"

```

简单的内容已经结束，开始复杂的编写，注意细节

#### 场景编写

task的作用是声明场景采集执行的步骤，其基础结构是一个 list

为什么task是一个 list？

- 是为了兼容不同版本可能导致的步骤的不同

task 的一个元素的结构如下

| 参数名 | 是否必填 |  |  | |
| --- | --- | --- | --- | --- |
| version | 否 | 表示适用的版本，使用方式见下示例 | 用str的形式表示范围，需要完整的数字的版本号，3.x版本为三位，4.x版本为四位如：[3.1.1,3.2.0]，版本支持遵循左开又闭的原则 | |
| steps | 是 | 所执行步骤 | 为list结构 | |

如下就是一个示例

```yaml
info: testinfo
task:
  - version: "[3.1.0,3.2.4]"
    steps:
    	{steps_object}
  - version: [4.2.0.0,4.3.0.0]
    steps:
    	{steps_object}

```

steps 又是一个 list ，用来表示具体的多个执行流程

steps 的一个元素的结构即单个流程，如下

| 参数名 | 是否必填 | |
| --- | --- | --- |
| type | 是 | 表示适用的执行类型，目前支持 ssh/sql/log/obproxy_log/sysstat, 后续会持续增加支持的类型 |
| {ssh/sql/log/obproxy_log/sysstat} | 是 | 根据所选的类型提供的参数，这块比较依赖代码里的对执行类型的逻辑说明，本章节后续会对支持的进行类型进行详细的使用说明 |

各种类型示例如下，"step:" 仅为一个标记，无实际作用

##### ssh

远程执行指令并获取对应的返回值

```yaml
step:
  type: ssh
  ssh: wc -l /proc/${task_OBServer_pid}/maps | awk '{print $1}'
  global: false # 此处的全局字段是相对于节点来说的，标记为true的时候只会在第一个节点执行的时候执行一次，如果标记为false则会在每个节点进行执行

```

##### sql

执行sql并获取对应的值

```yaml
step:
 type: sql
 sql: select tenant_name from oceanbase.__all_tenant;
 global: false

```

##### log

收集 observer 的日志

```yaml
step:
 type: log
 grep: "" # 过滤字段
 global: false

```

##### obproxy_log

收集 obproxy 的日志

```yaml
step:
 type: obproxy_log
 grep: "" # 过滤字段
 global: false

```

##### sysstat

收集主机的信息

```yaml
step:
 type: sysstat
 sysstat: ""
 global: false

```

#### 说明

global 字段是相对于节点来说的，标记为 true 的时候只会在第一个节点执行的时候执行一次，如果标记为 false 则会在每个节点进行执行

  上一篇 下一篇 ![有帮助](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*y6ocSqN8cqsAAAAAAAAAAAAAARQnAQ)![无帮助](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*BG9IQJyLHF8AAAAAAAAAAAAAARQnAQ)![反馈](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*eTWdQKCRKHwAAAAAAAAAAAAAARQnAQ)[AI](https://www.oceanbase.com/obi) 咨询热线
