Updated on 2024-09-11 GMT+08:00

Querying Slow Query Logs

Function

This API is used to query slow query logs. Before calling this API:

URI

POST /v3/{project_id}/instances/{instance_id}/clickhouse/slow-logs

Table 1 URI parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Project ID of a tenant in a region.

To obtain this value, see Obtaining a Project ID.

instance_id

Yes

String

ClickHouse instance ID, which is compliant with the UUID format.

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

User token.

To obtain this value, call the IAM API for obtaining a user token.

The value of X-Subject-Token in the response header is the token value.

X-Language

No

String

Request language type. The default value is en-us.

Values:

  • en-us
  • zh-cn
Table 3 Request body parameters

Parameter

Mandatory

Type

Description

node_id

Yes

String

Instance node ID.

start_time

Yes

String

Start time in the "yyyy-mm-ddThh:mm:ssZ" format.

T is the separator between the calendar and the hourly notation of time. Z indicates the time zone offset. For example, if the time zone offset is one hour, the value of Z is +0100.

end_time

Yes

String

Start time in the "yyyy-mm-ddThh:mm:ssZ" format.

T is the separator between the calendar and the hourly notation of time. Z indicates the time zone offset. For example, if the time zone offset is one hour, the value of Z is +0100.

limit

Yes

Integer

Number of records to be queried.

line_num

No

String

Sequence number of a log event. This parameter is not required for the first query, but is required for subsequent pagination queries. The value can be obtained from the response of the last query.

operate_type

No

String

Operation type of slow query logs.

database

No

String

Database name.

Response Parameters

Status code: 200

Table 4 Response body parameter

Parameter

Type

Description

slow_log_list

Array of slow_log_list objects

Slow query logs.

Table 5 slow_log_list

Parameter

Type

Description

node_id

String

ID of a ClickHouse instance node.

time

String

Execution time of a database statement.

lock_time

String

Lock wait time of a database statement.

rows_sent

Integer

Number of rows in each database statement execution result.

rows_examined

Integer

Number of rows scanned by a database statement.

database

String

Database name.

users

String

Account for executing statements.

query_sample

String

Database execution statements.

type

String

Database statement type.

client_ip

String

IP address.

start_time

String

Time when a database statement is executed.

line_num

String

Sequence number of a log event. This parameter is not required for the first query, but is required for subsequent pagination queries. The value can be obtained from the response of the last query.

count

String

Number of slow query logs.

Status code: 400

Table 6 Response body parameters

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error message.

Status code: 500

Table 7 Response body parameters

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error message.

Example Request

Querying slow query logs of the kernel

POST https://{endpoint}/v3/619d3e78f61b4be68bc5aa0b59edcf7b/instances/86fd60a5256a4592b957e8e6bb2d1b59in07/clickhouse/slow-logs

{
  "node_id" : "aeb9e81135b34197bab8636fc8a1c569no16",
  "start_time" : "2023-12-12T00:14:27+0100",
  "end_time" : "2023-12-12T02:14:27+0100",
  "limit" : "10",
  "line_num" : "1669344916000",
  "operate_type" : "All",
  "database" : "DBS_NODE"
}

Example Response

Status code: 200

Success.

{
  "slow_log_list" : [ {
    "node_id" : "941d21130b3c4899ad1a752a0945befdno07",
    "time" : "0.000143s",
    "rows_sent" : "10",
    "rows_examined" : "50",
    "database" : "user_center",
    "users" : "admin",
    "query_sample" : "sleep (N);",
    "type" : "1700755200000",
    "client_ip" : "10.1.1.60",
    "start_time" : "2023-08-28T08:22:13.591394+08:00",
    "line_num" : "1669344916000"
  } ]
}

Status Code

Status Code

Description

200

Success.

400

Client error.

500

Server error.

Error Code

For details, see Error Codes.