Skip to content

Commit

Permalink
Merge pull request #94 from Teingi/master
Browse files Browse the repository at this point in the history
1.6.0 release
  • Loading branch information
Teingi authored Feb 2, 2024
2 parents 692b17a + 6089c14 commit 76d9508
Show file tree
Hide file tree
Showing 100 changed files with 5,344 additions and 415 deletions.
9 changes: 8 additions & 1 deletion README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</a>
</p>

# Oceanbase Diagnostic Tool (obdiag)
# OceanBase Diagnostic Tool (obdiag)
OceanBase Diagnostic Tool (obdiag) 是一款专门OceanBase打造的敏捷诊断工具,功能包括诊断信息收集、分析、巡检,可以在OceanBase集群不同的部署模式下(OCP,OBD或用户根据文档手工部署)实现一键执行。

# 安装 obdiag
Expand Down Expand Up @@ -60,13 +60,17 @@ obdiag config -h <db_host> -u <sys_user> [-p password] [-P port]
## obdiag 巡检功能
- [一键巡检](./docs/check.md)

## obdiag 一键场景化信息采集功能
- [一键场景化信息采集](./docs/gather_scene.md)

## obdiag 一键信息采集功能

- [一键收集OB日志](./docs/gather_ob_log.md)
- [一键收集AWR报告](./docs/gather_awr.md)
- [一键收集主机信息](./docs/gather_sysstat.md)
- [一键收集slog/clog日志](./docs/gather_admin.md)
- [一键收集火焰图信息](./docs/gather_perf.md)
- [一键收集OB堆栈信息](./docs/gather_ob_stack.md)
- [一键收集并行SQL的执行详情信息](./docs/gather_sql_plan_monitor.md)
- [一键收集OBPROXY日志](./docs/gather_obproxy_log.md)
- [一键收集AWR报告](./docs/gather_awr.md)
Expand All @@ -76,6 +80,9 @@ obdiag config -h <db_host> -u <sys_user> [-p password] [-P port]
- [一键分析OB日志](./docs/analyze_ob_log.md)
- [一键全链路诊断](./docs/analyze_flt_trace.md)

## obdiag 一键场景化根因分析功能
- [一键场景化根因分析](./docs/rca.md)

# 许可证

OceanBase Diagnostic Tool 使用 [MulanPSL - 2.0](http://license.coscl.org.cn/MulanPSL2) 许可证。
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ English | [中文版](README-CN.md)
</a>
</p>


# Oceanbase Diagnostic Tool (obdiag)
# OceanBase Diagnostic Tool (obdiag)
OceanBase Diagnostic Tool (obdiag) is is a quick diagnostic tool for open-source OceanBase software. The features include gather\analyze\check OceanBase Diagnostic information. It can be executed with one click in different deployment modes of OceanBase clusters (OCP, OBD, or manually deployed by users according to documentation).

# Install obdiag
Expand Down Expand Up @@ -64,6 +63,9 @@ obdiag config -h <db_host> -u <sys_user> [-p password] [-P port]
## obdiag check Fuctions
- [check](./docs/check.md)

## obdiag gather scene Fuctions
- [gather scene](./docs/gather_scene.md)

## obdiag gather Fuctions

- [gather log](./docs/gather_ob_log.md)
Expand All @@ -80,6 +82,9 @@ obdiag config -h <db_host> -u <sys_user> [-p password] [-P port]
- [analyze log](./docs/analyze_ob_log.md)
- [analyze flt trace log](./docs/analyze_flt_trace.md)

## obdiag rca Fuctions
- [rca](./docs/rca.md)

# Licencing
OceanBase Database is under MulanPubL - 2.0 license. You can freely copy and use the source code. When you modify or
distribute the source code, please obey the MulanPubL - 2.0 license.
Expand Down
3 changes: 2 additions & 1 deletion clean_all_result.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
rm -rf ./gather_pack_*
rm -rf ./analyze_pack_*
rm -rf ./analyze_flt_result*
rm -rf ./analyze_flt_result*
rm -rf ./check_report
6 changes: 3 additions & 3 deletions common/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def get_observer_version(is_ssh, ssh_helper, ob_install_dir):
ob_version_info = SshClient().run_get_stderr(ssh_helper, cmd)
else:
ob_version_info = LocalClient().run_get_stderr(cmd)
logger.info("get observer version with LD_LIBRARY_PATH,cmd:{0}, result:{1}".format(cmd,ob_version_info))
logger.info("get observer version with LD_LIBRARY_PATH,cmd:{0}".format(cmd))
if "REVISION" not in ob_version_info:
raise Exception("Please check conf about observer,{0}".format(ob_version_info))
ob_version = re.findall(r'[(]OceanBase.CE\s(.+?)[)]', ob_version_info)[0]
Expand All @@ -355,7 +355,7 @@ def get_obproxy_version(is_ssh, ssh_helper, obproxy_install_dir):
obproxy_version_info = SshClient().run_get_stderr(ssh_helper, cmd)
else:
obproxy_version_info = LocalClient().run_get_stderr(cmd)
logger.info("get obproxy version, run cmd = [{0}] ".format(cmd))
logger.debug("get obproxy version, run cmd = [{0}] ".format(cmd))
if obproxy_version_info is not None:
ob_version = re.findall(r'[(]OceanBase.(.+? +?)[)]', obproxy_version_info)
if len(ob_version) > 0:
Expand All @@ -367,7 +367,7 @@ def get_obproxy_version(is_ssh, ssh_helper, obproxy_install_dir):
obproxy_version_info = SshClient().run_get_stderr(ssh_helper, cmd)
else:
obproxy_version_info = LocalClient().run_get_stderr(cmd)
logger.info("get obproxy version with LD_LIBRARY_PATH,cmd:{0}, result:{1}".format(cmd,obproxy_version_info))
logger.debug("get obproxy version with LD_LIBRARY_PATH,cmd:{0}, result:{1}".format(cmd,obproxy_version_info))
if "REVISION" not in obproxy_version_info:
raise Exception("Please check conf about proxy,{0}".format(obproxy_version_info))
pattern = r"(\d+\.\d+\.\d+\.\d+)"
Expand Down
13 changes: 12 additions & 1 deletion common/constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,19 @@ def __setattr__(self, name, value):
"tasks_base_path": "~/.obdiag/tasks/"
}
}

const.OBDIAG_GATHER_DEFAULT_CONFIG = {
"gather": {
"cases_base_path": "~/.obdiag/gather/tasks"
}
}

const.OBDIAG_RCA_DEFAULT_CONFIG = {
"rca": {
"result_path": "./rca/",
}
}
const.OBDIAG_TELEMETRY_FILE_NAME = os.path.expanduser("~/.obdiag/.obdiag_telemetry.txt")
const.TELEMETRY_CONTENT_REPORTER = "obdiag"
const.TELEMETRY_URL = "openwebapi.oceanbase.com"
const.TELEMETRY_PATH = "/api/web/oceanbase/report"

33 changes: 24 additions & 9 deletions common/ob_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,18 @@ def init(self):
logger.exception(e)

def _connect_db(self):
logger.debug("connect OB: {0}:{1} with user {2}".format(self.ip, self.port, self.username))
self.conn = mysql.connect(
host=self.ip,
port=self.port,
user=self.username,
passwd=self.password,
connect_timeout=30,
)
logger.debug("connect databse ...")
try:
logger.debug("connect OB: {0}:{1} with user {2}".format(self.ip, self.port, self.username))
self.conn = mysql.connect(
host=self.ip,
port=self.port,
user=self.username,
passwd=self.password,
connect_timeout=30,
)
logger.debug("connect databse ...")
except mysql.Error as e:
logger.error("connect OB: {0}:{1} with user {2} failed, error:{3}".format(self.ip, self.port, self.username, e))

def execute_sql(self, sql):
if self.conn is None:
Expand All @@ -58,6 +61,18 @@ def execute_sql(self, sql):
cursor.close()
return ret

def execute_sql_return_columns_and_data(self, sql):
if self.conn is None:
self._connect_db()
else:
self.conn.ping(reconnect=True)
cursor = self.conn.cursor()
cursor.execute(sql)
column_names = [col[0] for col in cursor.description]
ret = cursor.fetchall()
cursor.close()
return column_names, ret

def execute_sql_return_cursor_dictionary(self, sql):
if self.conn is None:
self._connect_db()
Expand Down
2 changes: 1 addition & 1 deletion common/obdiag_exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,4 @@ def __repr__(self):
return '%s %s' % (self.msg, self.obj is not None and pprint.pformat(self.obj) or '')

def __str__(self):
return repr(self)
return repr(self)
100 changes: 100 additions & 0 deletions common/scene.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#!/usr/bin/env python
# -*- coding: UTF-8 -*
# Copyright (c) 2022 OceanBase
# OceanBase Diagnostic Tool is licensed under Mulan PSL v2.
# You can use this software according to the terms and conditions of the Mulan PSL v2.
# You may obtain a copy of Mulan PSL v2 at:
# http://license.coscl.org.cn/MulanPSL2
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
# See the Mulan PSL v2 for more details.

"""
@time: 2024/01/16
@file: scene.py
@desc:
"""


from common.logger import logger
from utils.shell_utils import SshHelper
from utils.version_utils import compare_versions_greater
from common.command import get_observer_version, get_obproxy_version

def filter_by_version(scene, cluster):
try:
steps = scene
steps_nu = 0
# get observer version
if "version" not in cluster or cluster["version"] == "":
return steps_nu
for now_steps in steps:
if "version" in now_steps:
steps_versions = now_steps["version"]
if not isinstance(steps_versions, str):
logger.error("filter_by_version steps_version Exception : {0}".format("the type of version is not string"))
raise Exception("filter_by_version steps_version Exception : {0}".format("the type of version is not string"))
version_real = cluster["version"]
logger.info("version_int is {0} steps_versions is {1}".format(version_real, steps_versions))

steps_versions = steps_versions.replace(" ", "")
steps_versions = steps_versions[1:-1]
steps_versions_list = steps_versions.split(",")
minVersion = steps_versions_list[0]
maxVersion = steps_versions_list[1]
# min
if minVersion == "*":
minVersion = "-1"
if maxVersion == "*":
maxVersion = "999"
if compare_versions_greater(version_real, minVersion) and compare_versions_greater(maxVersion, version_real):
break
else:
logger.info("not version in now_steps")
break
steps_nu = steps_nu + 1
if steps_nu > len(steps) - 1:
logger.warning("not version in this scene")
return -1
return steps_nu
except Exception as e:
logger.error("filter_by_version Exception : {0}".format(e))
raise Exception("filter_by_version Exception : {0}".format(e))

def get_version(nodes, type):
try:
if len(nodes) < 1:
raise Exception("input nodes is empty, please check your config")
node = nodes[0]
ssh = SshHelper(True, node.get("ip"), node.get("user"), node.get("password"), node.get("port"), node.get("private_key"), node)
if type == "observer":
version = get_observer_version(True, ssh, nodes[0]["home_path"])
elif type == "obproxy":
version = get_obproxy_version(True, ssh, nodes[0]["home_path"])
return version
except Exception as e:
logger.error("can't get version, Exception: {0}".format(e))
raise Exception("can't get version, Exception: {0}".format(e))

def get_obproxy_and_ob_version(obproxy_nodes, nodes, type):
try:
if type == "observer" or type == "other":
if len(nodes) < 1:
raise Exception("input nodes is empty, please check your config")
node = nodes[0]
ssh = SshHelper(True, node.get("ip"), node.get("user"), node.get("password"), node.get("port"), node.get("private_key"), node)
version = get_observer_version(True, ssh, nodes[0]["home_path"])
elif type == "obproxy":
if len(nodes) < 1:
raise Exception("input obproxy nodes is empty, please check your config")
node = obproxy_nodes[0]
ssh = SshHelper(True, node.get("ip"), node.get("user"), node.get("password"), node.get("port"), node.get("private_key"), node)
version = get_obproxy_version(True, ssh, nodes[0]["home_path"])
else:
raise Exception(
"type is {0} . No func to get the version".format(type))
return version
except Exception as e:
logger.error("can't get version, Exception: {0}".format(e))
raise Exception("can't get version, Exception: {0}".format(e))
6 changes: 5 additions & 1 deletion conf/inner_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@ check:
report_path: "./check_report/"
export_type: table
package_file: "~/.obdiag/check_package.yaml"
tasks_base_path: "~/.obdiag/tasks/"
tasks_base_path: "~/.obdiag/tasks/"
gather:
scenes_base_path: "~/.obdiag/gather/tasks"
rca:
result_path: "./rca/"
6 changes: 3 additions & 3 deletions docs/check.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ observer ->check_package.yaml
obproxy ->obproxy_check_package.yaml


Example1:
Example:
obdiag check --cases= ad
obdiag check --obproxy_cases= proxy
obdiag check --cases=ad --obproxy_cases=proxy
```

### 关联持久化参数:
持久化参数主要是部分日常不会修改的参数,依赖于conf/config.yml
持久化参数主要是部分日常不会修改的参数,依赖于conf/inner_config.yml

若使用rpm方式进行安装,config.yml位于
```shell script
/user/local/oceanbase-diagnostic-tool/conf/config.yml
/user/local/oceanbase-diagnostic-tool/conf/inner_config.yml
```

check功能所关联的配置项在"CHECK"下,基本上的参数均无需变更或更改频率较低
Expand Down
11 changes: 11 additions & 0 deletions docs/gather_all.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,17 @@ Summary:
| 192.168.2.12 | Completed | 42.152K | 6 s | gather_pack_20220729170856/sysstat_192.168.2.12_20220729170856.zip |
+----------------+-----------+---------+--------+----------------------------------------------------------------------+


# observer当前的堆栈信息
Summary:
+----------------+-----------+---------+--------+-----------------------------------------------------------------------+
| Node | Status | Size | Time | PackPath |
+================+===========+=========+========+=======================================================================+
| 192.168.2.11 | Completed | 22.693K | 13 s | gather_pack_20220729170902/obstack2_192.168.2.11_20220729170902.zip |
+----------------+-----------+---------+--------+-----------------------------------------------------------------------+
| 192.168.2.12 | Completed | 19.902K | 13 s | gather_pack_20220729170902/obstack2_192.168.2.12_20220729170902.zip |
+----------------+-----------+---------+--------+-----------------------------------------------------------------------+

Gather Perf Summary:
+----------------+-----------+----------+--------+-------------------------------------------------------------------+
| Node | Status | Size | Time | PackPath |
Expand Down
4 changes: 2 additions & 2 deletions docs/gather_awr.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ optional arguments:
--cluster_name cluster_name
cluster name.
Example: obdiag gather awr --cluster_name demo1 --from 2022-06-16 18:25:00 --to 2022-06-16 18:30:00
Example: obdiag gather awr --from 2022-06-16 18:25:00 --to 2022-06-16 18:30:00
```

Expand All @@ -33,6 +33,6 @@ Gather AWR Summary:
+-----------+-----------+--------+--------+----------------------------------------------------------------------------------------+
| Cluster | Status | Size | Time | PackPath |
+===========+===========+========+========+========================================================================================+
| demo1 | Completed | 4.602M | 29 s | gather_pack_20220627005659/OBAWR_obcluster_jingshun_20220625160100_20220625180100.html |
| demo1 | Completed | 4.602M | 29 s | gather_pack_20220627005659/OBAWR_obcluster_demo1_20220625160100_20220625180100.html |
+-----------+-----------+--------+--------+----------------------------------------------------------------------------------------+
```
23 changes: 23 additions & 0 deletions docs/gather_ob_stack.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
## gather stack命令

收集observer的堆栈信息
```
$ obdiag gather stack [-h]
Example: obdiag gather stack
```

执行结果
```shell script
Example: obdiag gather stack

Summary:
+----------------+-----------+---------+--------+-----------------------------------------------------------------------+
| Node | Status | Size | Time | PackPath |
+================+===========+=========+========+=======================================================================+
| 192.168.2.11 | Completed | 19.926K | 10 s | gather_pack_20220729163951/obstack2_192.168.2.11_20220729163951.zip |
+----------------+-----------+---------+--------+-----------------------------------------------------------------------+
| 192.168.2.12 | Completed | 22.803K | 12 s | gather_pack_20220729163951/obstack2_192.168.2.11_20220729163951.zip |
+----------------+-----------+---------+--------+-----------------------------------------------------------------------+

```
Loading

0 comments on commit 76d9508

Please sign in to comment.