If OceanBase Diagnostic Tool (obdiag) is independently deployed, you can use obdiag check commands to inspect the status of an OceanBase cluster. The inspection process analyzes the cluster from perspectives of the system kernel parameters and internal tables, identifies the causes of existing or possible exceptions, and provides O&M suggestions.
Prerequisites
You have installed obdiag. For more information, see Install obdiag.
check commands
Syntax
obdiag check [options]
The following table describes the options.
| Option | Required? | Data type | Default value | Description |
|---|---|---|---|---|
| --cases | No | String | `` | The name of the collection of OBServer inspection items to be executed. If this option is not specified, all tasks are executed. |
| --obproxy_cases | No | String | `` | The name of the collection of OceanBase Database Proxy (ODP) inspection items to be executed. If this option is not specified, all tasks are executed. |
| -c | No | String | ~/.obdiag/config.yml |
The path of the configuration file. |
Here is an example:
obdiag check --cases=test
'cat ./check_report/check_report_2023-10-30-16:15:52.table', export type is table
For more details, please run cmd 'cat ./check_report/check_report_2023-10-30-16:15:52.table'
If you want to view detailed obdiag logs, please run:'obdiag display-trace --trace_id a7674ecb-0d99-36fe-b584-3b707b4647bc'
Tutorial for writing a task
A task is a specific inspection scenario. obdiag runs a task based on the dedicated script file in the YAML format.
The script file of a task contains a declaration at the beginning, which helps you implement professional inspections on an OceanBase cluster.
Preparations
Before you write the script file of a task, you must specify the path of the file.
The file must be saved in the directory specified by the CHECK.tasks_base_path parameter in the config.yml configuration file. Check whether the task falls into an existing category in the directory. If not, create a folder to declare the category.
Here is an example:
# Go to ${CHECK.tasks_base_path}/observer, create a folder named `test`, and then create a sample task script file named `test.yaml`.
cd ~/.obdiag/tasks/observer
mkdir test
cd test
touch test.yaml
Write the task script
The task script is a list that declares the steps to be executed in an inspection. You can specify steps for different versions of OceanBase Database, so the script can be used for inspections of OceanBase clusters of the specified versions.
Here is a sample task script:
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}
The following table describes the parameters.
| Parameter | Required? | Description |
|---|---|---|
| info | Yes | The scenario to use the task script file. This information facilitates maintenance. |
| version | No | The OceanBase Database version that the script is compatible with. The value is a range with complete version numbers in the form of a string. - The version number contains three digits for OceanBase Database V3.x, such as [3.1.1,3.2.0]. - The version number contains four digits for OceanBase Database V4.x, such as [4.1.0.0,4.2.0.0]. |
| steps | Yes | The list of steps to be executed. |
steps
steps is a list of multiple execution processes.
An element of steps is a single step that involves the following parameters.
| Parameter | Required? | Description |
|---|---|---|
| type | Yes | The type of the execution step. Valid values: get_system_parameter, ssh, and sql. |
| {parameter_name/ssh/sql} | Yes | The parameters for the selected type, which depend on the logic description of the execution type in the code. |
| result | No | An independent object that parses the operations to be performed after the current step ends, such as a verification result logic and the text information to be reported when the logic fails. For more information, see result & verify. |
In the following examples, step: serves only as a mark and has no actual meaning.
- get_system_parameter
steps:
- type: get_system_parameter
parameter_name: parameter
result:
set_value: servervm.max_map_count
- ssh
Remotely execute the instruction and obtain the corresponding return value.
steps:
- type: ssh
ssh: wc -l /proc/${task_OBServer_pid}/maps | awk '{print $1}'
result:
set_value: observerMaps
- sql
Execute an SQL statement and obtain the corresponding value.
steps:
- type: sql
sql: select tenant_name from oceanbase.table_name from where tenant_id=${taskTenantId};
result:
set_value: tenant_name
result & verify
This field is the main dependent field of the verify feature and is used to verify the task result.
The format of the result section is as follows:
result:
set_value: {set_value}
verify_type: {verify_type}
report_type: {report_type}
verify: {verify}
err_msg: {err_msg}
The following table describes the parameters.
| Parameter | Required? | Description |
|---|---|---|
| set_value | No | Evaluates the specified parameter as a variable applicable to the task after the task execution. For example, set_value: max_map_count. |
| verify_type | No | Specifies the verification method. The default value is base, which indicates to verify the result by using the expression specified by the verify parameter. The output is true or false. To reduce your coding workload, obdiag provides multiple types of verification methods. |
| verify | No | Verifies whether the execution result meets expectations based on the specified verification type. If not, the message specified by the err_msg parameter is returned. |
| report_type | No | The alert level returned if the verify parameter returns false. The default alert level is critical. |
| err_msg | No | The log used for recording execution errors. This parameter can be configured as a global variable. If the message output is configured with verify and the result of verify is false, an err_msg must be provided. |
Judgment types supported by verify_type:
At present, the judgment types supported by verify_type apply only the base and int types.
between: checks whether the value of the parameter specified by theset_valueparameter falls within the range specified by theverifyparameter.max: checks whether the value of the parameter specified by theset_valueparameter is less than that specified by theverifyparameter.min: checks whether the value of the parameter specified by theset_valueparameter is greater than that specified by theverifyparameter.equal: checks whether the value of the parameter specified by theset_valueparameter is equal to that specified by theverifyparameter.
base
You can replace new_expr with the expression specified by the verify parameter to manually verify the logic in your local environment.
if ${new_expr}; then
echo "true"
else
echo "false"
fi
Manually update tasks
We will update these tasks from time to time to provide more effective inspection tasks. To update your inspection package to the latest version, copy the ${code_path}/handler/check/tasks folder and the *check_package.yaml file from the code repository of obdiag to replace the original tasks folder and *check_package.yaml file in the ~/.obdiag/ directory.