This article applies to the scenario of independently deploying obdiag. Use the obdiag gather log command to collect the logs of the OceanBase cluster to which it belongs in one click.
If it is a cluster deployed by obd, you can directly collect information on the selected cluster through the obd side diagnostic command group.
Instructions for use
obdiag gather log [options]
The options are explained below:
Option name |
Is it required |
Data type |
Default value |
Description |
|---|---|---|---|---|
| --from | No | string | Default is empty | The start time of log collection, the format is: yyyy-mm-dd hh:mm:ss.
ExplanationIf the obdiag used is a version before V2.0.0, there is no need to add quotation marks when configuring this option, otherwise an error will be reported. V2.0.0 and later versions no longer limit whether to include quotes when configuring this option. |
| --to | No | string | Default is empty | The end time of log collection, the format is: yyyy-mm-dd hh:mm:ss.
ExplanationIf the obdiag used is a version before V2.0.0, there is no need to add quotation marks when configuring this option, otherwise an error will be reported. V2.0.0 and later versions no longer limit whether to include quotes when configuring this option. |
| --since | No | string | 30m |
Log collection for a recent period of time, the format is: <n><m|h|d>, where n is a number, m represents minutes, h represents hours, and d represents days. For example, 30m represents collecting the logs of the last 30 minutes. |
| --recent_count | No | int | 0 | Only collect the most recent N log files; --from, --to, --since are ignored when greater than 0. |
| --scope | No | string | all | Select the OceanBase cluster log type to collect. The configurable values are observer, election, rootservice, all. |
| --grep | No | string | Default is empty | Select keywords for query. |
| --store_dir | No | string | Defaults to the current path where the command is executed | The local path where the results are stored. |
| --temp_dir | No | string | /tmp |
The temporary file storage directory generated by the remote node during the log collection process. |
| --redact | No | string | Default is empty | Select the desensitization rule, for example, it can be configured as all_sql. When using multiple rules, use English commas (,) to separate them. To write the rules, refer to the introduction of this article [Preparation of desensitization rules] (#Preparation of desensitization rules). |
| -c | No | string | ~/.obdiag/config.yml |
Configuration file path. |
| --inner_config | No | string | Default is empty | obdiag's own configuration. Fixed style: --inner_config key1=value1 --inner_config key2=value2.
ExplanationFor parameters that support configuration through this option, please refer to the system configuration file (obdiag's own configuration) chapter. |
| --config | No | string | Default is empty | Configuration of the cluster to be diagnosed by obdiag, fixed style: --config key1=value1 --config key2=value2.
ExplanationThe parameters that support configuration through this option can be found in obdiag configuration. |
| --config_password | No | string | Default is empty | obdiag When using an encrypted configuration file, you need to pass in the corresponding password through this option.
ExplanationFor details, see Configuration file encryption. |
Usage example
Method 1: Use without configuration file (out of the box)
- Collect logs for a specified period of time
obdiag gather log --from "2022-06-30 16:25:00" --to "2022-06-30 18:30:00" \
--config obcluster.servers.nodes[0].ip=xx.xx.xx.1 \
--config obcluster.servers.nodes[1].ip=xx.xx.xx.2 \
--config obcluster.servers.global.ssh_username=test \
--config obcluster.servers.global.ssh_password=****** \
--config obcluster.servers.global.home_path=/home/admin/oceanbase
The output is as follows:
...
ZipFileInfo:
+-------------------+-----------+
| Node | LogSize |
+===================+===========+
| xxx.xxx.xxx.xxx | 36.184M |
+-------------------+-----------+
...
ZipFileInfo:
+-------------------+-----------+
| Node | LogSize |
+===================+===========+
| xxx.xxx.xxx.xxx | 44.176M |
+-------------------+-----------+
...
Summary:
+-------------------+-----------+----------+--------+-------------------------------------------------------------------------------+
| Node | Status | Size | Time | PackPath |
+===================+===========+==========+========+===============================================================================+
| xxx.xxx.xxx.xxx | Completed | 36.762M | 19 s | obdiag_gather_pack_20220701183246/ob_log_xxx.xxx.xxx.xxx_20220701183247.zip |
+-------------------+-----------+----------+--------+-------------------------------------------------------------------------------+
| xxx.xxx.xxx.xxx | Completed | 638.200M | 718 s | obdiag_gather_pack_20220701183246/ob_log_xxx.xxx.xxx.xxx_20220701183918.zip |
+-------------------+-----------+----------+--------+-------------------------------------------------------------------------------+
```* Quickly collect logs from the most recent period
```shell
# Passwordless SSH to targets: collect last 1h of logs
obdiag gather log --since 1h \
--config obcluster.servers.nodes[0].ip=xx.xx.xx.1 \
--config obcluster.servers.nodes[1].ip=xx.xx.xx.2 \
--config obcluster.servers.nodes[2].ip=xx.xx.xx.3 \
--config obcluster.servers.global.home_path=/home/admin/oceanbase
# Passwordless: last 1h; cap 300MB and 5 files per node (skip node if exceeded)
obdiag gather log --since 1h \
--config obcluster.servers.nodes[0].ip=xx.xx.xx.1 \
--config obcluster.servers.nodes[1].ip=xx.xx.xx.2 \
--config obcluster.servers.nodes[2].ip=xx.xx.xx.3 \
--config obcluster.servers.global.home_path=/home/admin/oceanbase \
--inner_config obdiag.basic.file_number_limit=5
--inner_config obdiag.basic.file_size_limit=300M
# Passwordless: last 1h; cap 1GB and 5 files per node (skip node if exceeded)
obdiag gather log --since 1h \
--config obcluster.servers.nodes[0].ip=xx.xx.xx.1 \
--config obcluster.servers.nodes[1].ip=xx.xx.xx.2 \
--config obcluster.servers.nodes[2].ip=xx.xx.xx.3 \
--config obcluster.servers.global.home_path=/home/admin/oceanbase \
--inner_config obdiag.basic.file_number_limit=5
--inner_config obdiag.basic.file_size_limit=1G
# Passwordless: collect last 30m of logs
obdiag gather log --since 30m \
--config obcluster.servers.nodes[0].ip=xx.xx.xx.1 \
--config obcluster.servers.nodes[1].ip=xx.xx.xx.2 \
--config obcluster.servers.nodes[2].ip=xx.xx.xx.3 \
--config obcluster.servers.global.home_path=/home/admin/oceanbase
# When OBServer nodes differ: collect last 30m of logs
obdiag gather log --since 30m \
--config obcluster.servers.nodes[0].ip=xx.xx.xx.1 \
--config obcluster.servers.nodes[0].ssh_username=test1 \
--config obcluster.servers.nodes[0].ssh_password=****** \
--config obcluster.servers.nodes[0].home_path=/home/test1/oceanbase \
--config obcluster.servers.nodes[1].ip=xx.xx.xx.2
--config obcluster.servers.nodes[1].ssh_username=test2 \
--config obcluster.servers.nodes[1].ssh_password=****** \
--config obcluster.servers.nodes[1].home_path=/home/test2/oceanbase
# Provide sys tenant conn string; obdiag resolves nodes and collects last 1h
obdiag gather log --since 1h \
--config db_host=xx.xx.xx.xx \
--config db_port=xxxx \
--config tenant_sys.user=root@sys \
--config tenant_sys.password=*** \
--config obcluster.servers.global.ssh_username=test \
--config obcluster.servers.global.ssh_password=****** \
--config obcluster.servers.global.home_path=/home/admin/oceanbase
```* Filter keyword collection
```shell
# Collect last 30m of logs filtered by keyword TRACE_ID
obdiag gather log --grep "TRACE_ID" \
--config db_host=xx.xx.xx.xx \
--config db_port=xxxx \
--config tenant_sys.user=root@sys \
--config tenant_sys.password=*** \
--config obcluster.servers.global.ssh_username=test \
--config obcluster.servers.global.ssh_password=****** \
--config obcluster.servers.global.home_path=/home/admin/oceanbase
# Collect last 30m filtered by multiple keywords e.g. AAAAA and BBBBB
obdiag gather log --grep "AAAAA" --grep "BBBBB" \
--config db_host=xx.xx.xx.xx \
--config db_port=xxxx \
--config tenant_sys.user=root@sys \
--config tenant_sys.password=*** \
--config obcluster.servers.global.ssh_username=test \
--config obcluster.servers.global.ssh_password=****** \
--config obcluster.servers.global.home_path=/home/admin/oceanbase
# Collect given time range with multiple keyword filters
obdiag gather log --from "2022-06-30 16:25:00" --to "2022-06-30 18:30:00" --grep "AAAAA" --grep "BBBBB" \
--config db_host=xx.xx.xx.xx \
--config db_port=xxxx \
--config tenant_sys.user=root@sys \
--config tenant_sys.password=*** \
--config obcluster.servers.global.ssh_username=test \
--config obcluster.servers.global.ssh_password=****** \
--config obcluster.servers.global.home_path=/home/admin/oceanbase
```<main id="notice" type='notice'>
<h4>Attention</h4>
<p> If multiple keywords are used for filtering, the relationship between them is an "AND" relationship. Only the collected log lines that satisfy multiple keywords in grep will be collected. </p>
</main>
### Method 2: Use with configuration file
You need to ensure that the login information of the node to be collected has been configured in the obdiag configuration file <code>~/.obdiag/config.yml</code>. For related detailed configuration introduction, see [obdiag configuration](../../300.obdiag-config-guide.md).
* Collect logs for a specified period of time
```shell
obdiag gather log --from "2022-06-30 16:25:00" --to "2022-06-30 18:30:00"
The output is as follows:
...
ZipFileInfo:
+-------------------+-----------+
| Node | LogSize |
+===================+===========+
| xxx.xxx.xxx.xxx | 36.184M |
+-------------------+-----------+
...
ZipFileInfo:
+-------------------+-----------+
| Node | LogSize |
+===================+===========+
| xxx.xxx.xxx.xxx | 44.176M |
+-------------------+-----------+
...
Summary:
+-------------------+-----------+----------+--------+-------------------------------------------------------------------------------+
| Node | Status | Size | Time | PackPath |
+===================+===========+==========+========+===============================================================================+
| xxx.xxx.xxx.xxx | Completed | 36.762M | 19 s | obdiag_gather_pack_20220701183246/ob_log_xxx.xxx.xxx.xxx_20220701183247.zip |
+-------------------+-----------+----------+--------+-------------------------------------------------------------------------------+
| xxx.xxx.xxx.xxx | Completed | 638.200M | 718 s | obdiag_gather_pack_20220701183246/ob_log_xxx.xxx.xxx.xxx_20220701183918.zip |
+-------------------+-----------+----------+--------+-------------------------------------------------------------------------------+
```* Quickly collect logs from the most recent period
```shell
# Collect last 1h of logs
obdiag gather log --since 1h
# Collect last 30m of logs
obdiag gather log --since 30m
# Collect last 30m with explicit cluster config file
obdiag gather log --since 30m -c /root/config.yml
```* Filter keyword collection
```shell
# Collect last 30m of logs filtered by keyword TRACE_ID
obdiag gather log --grep "TRACE_ID"
# Collect last 30m filtered by multiple keywords e.g. AAAAA and BBBBB
obdiag gather log --grep "AAAAA" --grep "BBBBB"
# Collect given time range with multiple keyword filters
obdiag gather log --from "2022-06-30 16:25:00" --to "2022-06-30 18:30:00" --grep "AAAAA" --grep "BBBBB"
```<main id="notice" type='notice'>
<h4>Attention</h4>
<p> If multiple keywords are used for filtering, the relationship between them is an "AND" relationship. Only the collected log lines that satisfy multiple keywords in grep will be collected. </p>
</main>
## Interpretation of results
After the command is executed, a folder will be generated in the specified directory. The folder looks like: obdiag_gather_pack_20240808105846
## Writing desensitization rules
In many cases, masking rules are defined by the business side, that is, users define what sensitive data is. Obdiag began to support custom masking rules in version 2.5.0. The files about desensitization rules in obdiag are located under `~/.obdiag/gather/redact/`. All py files are corresponding rules, and the file name is the rule name.
This time we use `a_test` as an example to introduce how to write desensitization rules.
1. Create a rule file
Create a py file under `~/.obdiag/gather/redact/`. When writing rules, we stipulate that the file name is the rule name. In this example, the file name is `a_test.py`, which creates `~/.obdiag/gather/redact/a_test.py`.
2. Create a unified class
In order to facilitate unified management in the future, you need to create a rule class that inherits the RedactBase class. The class name can be customized and is generally consistent with the file name. The example is as follows:``` shell
from handler.gather.plugins.redact import RedactBase
class a_test(RedactBase):
```3. Create rule methods
Our rule class needs to implement the redact method. text is the input file content (not separated into lines). If branch processing is required, just perform branch processing, as follows:
```shell
text_lines = text.split('\n')
```4. Return the processed information in the form of string
It should be noted that branch processing will cause the processing time to increase significantly. It is recommended not to do this unless the demand is strong.
5. Create a rule instance
According to the rules of obdiag, a variable with a rule name needs to be set for calling the obdiag kernel. According to the example, a variable of a_test needs to be added. The specific implementation is as follows:
```shell
a_test = a_test()
Complete example
from handler.gather.plugins.redact import RedactBase
import re
class a_test(RedactBase):
def redact(self, text):
text_lines = text.split('\n')
redacted_log = ''
for line in text_lines:
if 'test' in line:
redacted_log = redacted_log + re.sub('test', '******', line)
return redacted_log
a_test = a_test()
