Queries entries in slow query logs of an ApsaraDB for MongoDB instance.

  • This operation is applicable to replica set instances and sharded cluster instances.
  • You can call this operation up to 30 times per minute. To call this operation at a higher frequency, use a Logstore. For more information, see Manage a Logstore.
  • If the instance is purchased after June 6, 2021 and you want to view its slow query logs, you must enable the audit logs feature and select the admin and slow operation types that you want to audit. You can only view slow query logs that are generated after the audit logs feature is enabled.
    Note
    • You can call the ModifyAuditPolicy operation to enable or disable the audit logs feature.
    • You can call the ModifyAuditLogFilter operation to set the operation types that you want to audit.

Debugging

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer. OpenAPI Explorer dynamically generates the sample code of the operation for different SDKs.

Request parameters

Parameter Type Required Example Description
Action String Yes DescribeSlowLogRecords

The operation that you want to perform. Set the value to DescribeSlowLogRecords.

RegionId String No cn-hangzhou

The region ID of the instance.

Note You can call the DescribeDBInstanceAttribute operation to query the region ID of the instance.
DBInstanceId String Yes dds-bp1fc7e65108****

The ID of the instance.

Note If you specify this parameter to the ID of a sharded cluster instance, you must also specify the NodeId parameter.
NodeId String No d-bp18b06ebc21****

The ID of the shard node.

Note This parameter takes effect only when you specify the DBInstanceId parameter to the ID of a sharded cluster instance.
StartTime String Yes 2019-02-24T 12:10:10Z

The beginning of the time range to query. Specify the time in the yyyy-MM-ddTHH:mm:ssZ format. The time must be in UTC.

EndTime String Yes 2019-02-24T 13:10:10Z

The end of the time range to query. Specify the time in the yyyy-MM-ddTHH:mm:ssZ format. The time must be in UTC.

Note
  • The end time must be later than the start time.
  • The end time must be within 24 hours from the start time. Otherwise, the query fails.
DBName String No mongodbtest

The name of the database.

PageSize Integer No 30

The number of entries to return on each page. Valid values: 30 to 100.

PageNumber Integer No 1

The number of the page to return. The value must be an integer that is larger than 0. Default value: 1.

OrderType String No asc

The order of time in which the log entries to return are sorted. Valid values:

  • asc: The log entries are sorted by time in ascending order.
  • desc: The log entries are sorted by time in descending order.
ResourceGroupId String No rg-acfmyiu4ekp****

The ID of the resource group to which the instance belongs.

Response parameters

Parameter Type Example Description
TotalRecordCount Integer 1

The total number of records that were returned.

PageRecordCount Integer 1

The number of slow query log entries on the page.

RequestId String 414A4E5-4C36-4461-95FC-23757A20****

The ID of the request.

PageNumber Integer 1

The page number of the returned page. The value must be an integer that is greater than 0. Default value: 1.

Items Array of LogRecords

Details about the slow query logs.

LogRecords
ExecutionStartTime String 2019-02-25T 01:41:28Z

The start time of the operation. The time is in the yyyy-MM-ddTHH:mm:ssZ format. The time is displayed in UTC.

HostAddress String 192.168.XX.XX

The host IP address that is used to connect to the database.

QueryTimes String 600

The execution time of the statement. Unit: milliseconds.

TableName String C1

The name of the collection.

SQLText String {\"op\":\"query\",\"ns\":\"mongodbtest.customer\",\"query\":{\"find\":\"customer\",\"filter\":{\"name\":\"jack\"}}}

The SQL statement that is executed during the slow operation.

ReturnRowCounts Long 0

The number of returned rows.

KeysExamined Long 0

The data entries that are scanned during indexing.

DBName String mongodbtest

The name of the database.

DocsExamined Long 1000000

The number of documents that are scanned during the operation.

AccountName String root

The user name of the database account that performs the operation.

Engine String MongoDB

The database engine.

Examples

Sample requests

http(s)://mongodb.aliyuncs.com/?Action=DescribeSlowLogRecords
&DBInstanceId=dds-bp1fc7e65108****
&NodeId=d-bp18b06ebc21****
&StartTime=2019-02-24T 12:10:10Z
&EndTime=2019-02-24T 13:10:10Z
&DBName=mongodbtest
&PageSize=30
&PageNumber=1
&OrderType=asc
&ResourceGroupId=rg-acfmyiu4ekp****
&<Common request parameters>

Sample success responses

XML format

HTTP/1.1 200 OK
Content-Type:application/xml

<DescribeSlowLogRecordsResponse>
    <TotalRecordCount>1</TotalRecordCount>
    <PageRecordCount>1</PageRecordCount>
    <RequestId>414A4E5-4C36-4461-95FC-23757A20****</RequestId>
    <PageNumber>1</PageNumber>
    <Items>
        <ExecutionStartTime>2019-02-25T 01:41:28Z</ExecutionStartTime>
        <HostAddress>192.168.XX.XX</HostAddress>
        <QueryTimes>600</QueryTimes>
        <TableName>C1</TableName>
        <SQLText>{\"op\":\"query\",\"ns\":\"mongodbtest.customer\",\"query\":{\"find\":\"customer\",\"filter\":{\"name\":\"jack\"}}}</SQLText>
        <ReturnRowCounts>0</ReturnRowCounts>
        <KeysExamined>0</KeysExamined>
        <DBName>mongodbtest</DBName>
        <DocsExamined>1000000</DocsExamined>
        <AccountName>root</AccountName>
    </Items>
    <Engine>MongoDB</Engine>
</DescribeSlowLogRecordsResponse>

JSON format

HTTP/1.1 200 OK
Content-Type:application/json

{
  "TotalRecordCount" : 1,
  "PageRecordCount" : 1,
  "RequestId" : "414A4E5-4C36-4461-95FC-23757A20****",
  "PageNumber" : 1,
  "Items" : [ {
    "ExecutionStartTime" : "2019-02-25T 01:41:28Z",
    "HostAddress" : "192.168.XX.XX",
    "QueryTimes" : "600",
    "TableName" : "C1",
    "SQLText" : "{\\\"op\\\":\\\"query\\\",\\\"ns\\\":\\\"mongodbtest.customer\\\",\\\"query\\\":{\\\"find\\\":\\\"customer\\\",\\\"filter\\\":{\\\"name\\\":\\\"jack\\\"}}}",
    "ReturnRowCounts" : 0,
    "KeysExamined" : 0,
    "DBName" : "mongodbtest",
    "DocsExamined" : 1000000,
    "AccountName" : "root"
  } ],
  "Engine" : "MongoDB"
}

Error codes

For a list of error codes, visit the API Error Center.