Updated on 2023-11-24 GMT+08:00

Querying Database Slow Logs (New)

API Description

This API is used to query slow logs by keyword or database table name.

Restrictions

  • Operators (such as &&, ||, AND, OR, NOT, *, ?, :, >, <, =, , and ) contained in raw logs cannot be used to search for logs.
  • A maximum of 100 records can be queried on each page.
  • Slow query logs can be stored for a maximum of 30 days.

URI

  • URI format

    POST https://{Endpoint}/v3.1/{project_id}/instances/{instance_id}/slow-logs

  • URI example

    https://dds.ap-southeast-1.myhuaweicloud.com/v3.1/0483b6b16e954cb88930a360d2c4e663/instances/6ade8143870047b8999aba8f1891b48ein02/slow-logs

Table 1 Request parameters

Name

Type

IN

Mandatory

Description

X-Auth-Token

string

header

Yes

User token obtained from IAM. For details, see Authentication.

project_id

string

path

Yes

Project ID of a tenant in a region. To obtain the project ID, see Obtaining a Project ID.

instance_id

string

path

Yes

Instance ID, which can be obtained by calling the API described in Querying Instances and Details. If you do not have an instance, call the API described in Creating a DB Instance to create one.

Requests

  • Parameter description
    Table 2 Parameter description

    Name

    Type

    Mandatory

    Description

    start_time

    String

    Yes

    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.

    CAUTION:

    The start time cannot be 30 days earlier than the current time.

    end_time

    String

    Yes

    End 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.

    NOTE:

    The end time cannot be later than the current time.

    limit

    Integer

    Yes

    Number of logs to be queried each time. The maximum value is 100.

    line_num

    String

    No

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

    NOTE:

    The current query starts from the next log of line_num, excluding the log of line_num.

    operate_type

    String

    No

    Statement type. If this parameter is left empty, all statement types are queried.

    Its value can be any of the following:

    • insert
    • query
    • update
    • remove
    • getmore
    • command
    • killcursors

    node_id

    String

    No

    Node ID. For details, see Table 8.

    If this parameter is left blank, all nodes in the instance can be queried.

    Nodes that can be queried:

    Shard nodes in a cluster instance.

    All nodes in a replica set or single node instance.

    keywords

    Array of strings

    No

    Full-text log search based on multiple keywords, indicating that all keywords are matched.

    • Only fuzzy search by keyword prefix is supported. A maximum of 10 keywords are supported.
    • Each keyword can contain a maximum of 512 characters.

    database_keywords

    Array of strings

    No

    Fuzzy search for logs based on multiple database keywords, indicating that at least one keyword is matched.

    • Only fuzzy search by keyword prefix is supported. A maximum of 10 keywords are supported.
    • Each keyword can contain a maximum of 64 characters.

    collection_keywords

    Array of strings

    No

    Fuzzy search for logs based on multiple database table name keywords, indicating that at least one keyword is matched.

    • Only fuzzy search by keyword prefix is supported. A maximum of 10 keywords are supported.
    • Each keyword can contain a maximum of 128 characters.

    max_cost_time

    Integer

    No

    Logs can be searched based on the maximum execution duration.

    Unit: ms

    min_cost_time

    Integer

    No

    Logs can be searched based on the minimum execution duration.

    Unit: ms

Example Request

Querying slow logs of a DB instance by keyword, in which limit is set to 100, max_cost_time is set to 100, and min_cost_time is set to 50
{ 
  "start_time" : "2022-09-06T10:41:14+0800", 
  "end_time" : "2022-09-16T10:41:14+0800", 
  "limit" : 100, 
  "line_num" : "1595659490239433658", 
  "operate_type" : "query",
  "node_id" : "dbd0b65ed0c34125a0b04d4e5ba67e66no02", 
  "keywords" : [ "response", "oplog" ],
  "database_keywords" : [ "testDB" ], 
  "collection_keywords" : [ "testCollection" ], 
  "max_cost_time" : 100, 
  "min_cost_time" : 50
}

Responses

  • Parameter description
    Table 3 Parameter description

    Name

    Type

    Description

    slow_logs

    Array of objects

    Slow log information.

    For details, see Table 4.

    Table 4 Data structure description of field slowLogDetail

    Name

    Type

    Description

    node_name

    String

    Node name.

    node_id

    String

    Node ID.

    whole_message

    String

    Statement.

    operate_type

    String

    Statement type.

    cost_time

    Integer

    Execution time.

    Unit: ms

    lock_time

    Integer

    Lock wait time.

    Unit: μs

    docs_returned

    Integer

    Number of returned documents.

    docs_scanned

    Integer

    Number of scanned documents.

    database

    String

    Name of the database which the log belongs to.

    collection

    String

    Name of the database table which the log belongs to.

    log_time

    String

    UTC time when a log is generated. The format is yyyy-mm-ddThh:mm:ssZ. T is the separator between the calendar and the hourly notation of time. Z indicates the time zone offset.

    line_num

    String

    Sequence number of a log event.

  • Example response
    { 
      "slow_logs" : [ { 
        "node_name" : "Test_replica_node_2", 
        "node_id" : "dbd0b65ed0c34125a0b04d4e5ba67e66no02", 
        "whole_message" : "{\"responseLength\": 230, \"ts\": {\"$date\": 1605480486800}, \"ninserted\": 1, \"locks\": {\"oplog\": {\"acquireCount\": {\"w\": 1}}, \"Global\": {\"acquireCount\": {\"r\": 3, \"w\": 2}}, \"Collection\": {\"acquireCount\": {\"w\": 2}}, \"Database\": {\"acquireCount\": {\"w\": 3}}}, \"numYield\": 0, \"ns\": \"geographySpace.tiles\"}", 
        "operate_type" : "query", 
        "cost_time" : 60, 
        "lock_time" : 10, 
        "docs_returned" : 60, 
        "docs_scanned" : 70, 
        "database" : "testDB", 
        "collection" : "testCollection", 
        "log_time" : "2022-09-15T22:49:38.643000Z", 
        "line_num" : "1595659490239433659" 
      } ] 
    }

SDK

Click Document Database Service DDS SDK to download the SDK or view the SDK document. To learn how to install and authenticate an SDK, read the Usage section.

Status Code

For more information, see Status Code.

Error Code

For more information, see Error Code.