title | summary |
---|---|
TiProxy Command-Line Flags |
Learn the command-line startup flags of TiProxy. |
This document introduces the command-line flags that you can use when you launch TiProxy. It also introduces flags of tiproxyctl
.
This section lists the flags of the server program tiproxy
.
- Specifies the address that clients use to connect to this TiProxy instance.
- Type:
string
- Default:
""
- This flag is automatically set when you deploy TiProxy using TiUP or TiDB Operator. If not set, the external IP address of the TiProxy instance is used.
- Specifies the path of the TiProxy configuration file.
- Type:
string
- Default:
""
- You must specify the configuration file. For detailed configuration items, refer to Configure TiProxy. Note that TiProxy automatically reloads the configuration when the configuration file is modified. Therefore, do not directly modify the configuration file. It is recommended to modify the configuration by executing
tiup cluster edit-config
orkubectl edit tc
.
This section introduces the installation methods, syntax, options, and commands of the client program tiproxyctl
.
You can install TiProxy Control using one of the following two methods.
Note:
TiProxy Control is specifically designed for debugging purposes and might not be fully compatible with future capabilities introduced in TiProxy. It's not recommended to include this tool in application or utility development to get information.
After installing TiUP, you can use the tiup install tiproxy
command to download and install the binary programs for TiProxy and TiProxy Control. After installation, you can use tiup --binary tiproxy
to view the installation path of TiProxy. TiProxy Control is located in the same directory as TiProxy.
For example:
tiup install tiproxy
# download https://tiup-mirrors.pingcap.com/tiproxy-v1.3.0-linux-amd64.tar.gz 22.51 MiB / 22.51 MiB 100.00% 13.99 MiB/s
ls `tiup --binary tiproxy`ctl
# /root/.tiup/components/tiproxy/v1.3.0/tiproxyctl
Compilation environment requirement: Go 1.21 or later
Compilation procedures: Go to the root directory of the TiProxy project, use the make
command to compile and generate tiproxyctl
.
git clone https://github.com/pingcap/tiproxy.git
cd tiproxy
make
ls bin/tiproxyctl
tiproxyctl [flags] [command]
For example:
tiproxyctl --host 127.0.0.1 --port 3080 config get
- Specifies the TiProxy server address.
- Type:
string
- Default:
localhost
- Specifies the port number of the TiProxy API gateway.
- Type:
int
- Default:
3080
-
Specifies the log format of
tiproxyctl
. -
Type:
string
-
Default:
"tidb"
-
It defaults to the same log format of TiDB. However, you can also specify it as one of the following:
console
: a more human-readable formatjson
: a structured log format
- Specifies the log level of tiproxyctl.
- Type:
string
- Default:
"warn"
- You can specify
debug
,info
,warn
,error
,panic
.
- Specifies whether to skip TLS CA verification when dialing to the server.
- Type:
boolean
- Default:
false
- Used for testing.
- Specifies the CA when dialing to the server.
- Type:
string
- Default:
""
- Specifies the certificate when dialing to the server.
- Type:
string
- Default:
""
The tiproxyctl config set
command reads a TOML-formatted configuration file from standard input and sets these configuration items to TiProxy. Unspecified configuration items will remain unchanged, so you only need to specify the items that you want to modify.
The following example sets log.level
as 'warning'
, while leaving other configuration items unchanged.
$ cat test.toml
[log]
level='warning'
$ cat test.toml | tiproxyctl config set
""
$ tiproxyctl config get | grep level
level = 'warning'
The tiproxyctl config get
command is used to get the current TiProxy configuration in TOML format.
The tiproxyctl health
command is used to get the health status of TiProxy and the checksum of the configuration. When TiProxy is running normally, it returns the checksum of the configuration. When TiProxy is shutting down or offline, it returns an error.
Example output:
{"config_checksum":3006078629}
The tiproxyctl traffic capture
command is used to capture traffic.
Options:
--output
: (required) specifies the directory to store traffic files.--duration
: (required) specifies the duration of capture. The unit is one ofm
(minutes),h
(hours), ord
(days). For example,--duration=1h
captures traffic for one hour.--compress
: (optional) specifies whether to compress traffic files.true
means compression, and the compression format is gzip.false
means no compression. The default value istrue
.--encryption-method
: (optional) specifies the algorithm for encrypting traffic files. Only""
,plaintext
, andaes256-ctr
are supported.""
andplaintext
indicate no encryption, andaes256-ctr
indicates encryption using theAES256-CTR
algorithm. When specifying encryption, you also need to configureencryption-key-path
. The default value is""
.
Example:
The following command connects to the TiProxy instance at 10.0.1.10:3080
, captures traffic for one hour, and saves it to the /tmp/traffic
directory on the TiProxy instance:
tiproxyctl traffic capture --host 10.0.1.10 --port 3080 --output="/tmp/traffic" --duration=1h
The tiproxyctl traffic replay
command is used to replay captured traffic.
Options:
--username
: (required) specifies the database username for replay.--password
: (optional) specifies the password for the username. If not specified, you need to enter the password in an interactive mode.--input
: (required) specifies the directory containing traffic files.--speed
: (optional) specifies the replay speed multiplier. The range is[0.1, 10]
. The default value is1
, indicating replay at the original speed.--read-only
: (optional) specifies whether to replay only read-only SQL statements.true
means to replay only read-only SQL statements, andfalse
means to replay all SQL statements. The default value isfalse
.
Example:
The following command connects to the TiProxy instance at 10.0.1.10:3080
using username u1
and password 123456
, reads traffic files from the /tmp/traffic
directory on the TiProxy instance, and replays the traffic at twice the original speed:
tiproxyctl traffic replay --host 10.0.1.10 --port 3080 --username="u1" --password="123456" --input="/tmp/traffic" --speed=2
The tiproxyctl traffic cancel
command is used to cancel the current capture or replay job.
The tiproxyctl traffic show
command is used to display historical capture and replay jobs. It outputs an array of objects, and each object represents a job. Each job has the following fields:
type
: the job type.capture
indicates a traffic capture job,replay
indicates a traffic replay jobstatus
: the current status of the job.running
indicates in progress,done
indicates normal completion, andcanceled
indicates job failure..start_time
: the start time of the jobend_time
: the end time if the job has completed. Otherwise, it is empty.progress
: the completion percentage of the joberror
: if the job fails, this column contains the reason for the failure. Otherwise, it is empty. For example,manually stopped
means the user manually cancels the job by executingCANCEL TRAFFIC JOBS
.output
: the output traffic file path of the capture jobduration
: the duration of the traffic capture jobcompress
: whether the traffic files are compressedencryption_method
: the encryption method of the traffic fileinput
: the input traffic file path of the replay jobusername
: the database username for traffic replayspeed
: the replay speed multiplierread_only
: whether only replays read-only statements
Example output:
[
{
"type": "capture",
"status": "done",
"start_time": "2024-09-01T14:30:40.99096+08:00",
"end_time": "2024-09-01T16:30:40.99096+08:00",
"progress": "100%",
"output": "/tmp/traffic",
"duration": "2h",
"compress": true
},
{
"type": "capture",
"status": "canceled",
"start_time": "2024-09-02T18:30:40.99096+08:00",
"end_time": "2024-09-02T19:00:40.99096+08:00",
"progress": "25%",
"error": "manually stopped",
"output": "/tmp/traffic",
"duration": "2h"
},
{
"type": "capture",
"status": "running",
"start_time": "2024-09-03T13:31:40.99096+08:00",
"progress": "45%",
"output": "/tmp/traffic",
"duration": "2h"
}
]