This topic describes how to view slow query logs of ApsaraDB for MongoDB instances. You can identify, analyze, diagnose, and track slow query logs to create indexes. This improves the utilization of the instance resources.

Prerequisites

A replica set instance or sharded cluster instance that runs MongoDB 4.2 or later is created.

Precautions

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.

Procedure

  1. Log on to the ApsaraDB for MongoDB console.
  2. In the upper-left corner of the page, select the resource group and the region of the target instance.
  3. In the left-side navigation pane, click Replica Set Instances, or Sharded Cluster Instances based on the instance type.
  4. Find the target instance and click its ID.
  5. In the left-side navigation pane, choose CloudDBA > Slow Query Logs.
    Note By default, slow query logs generated in the past 15 minutes are displayed in the trend chart. You can specify the time range and click Search to view slow query logs. The maximum time range is one day.
  6. View details of slow query logs based on the following methods:
    Method 1
    1. Click the Slow Log Details tab under the trend chart.
    2. On the Slow Log Details tab, select the database that you want to query.
      Note If the request content of the database is hidden, you can move the pointer over the corresponding content in the Request Content column and view the complete content.
    Method 2
    1. In the trend chart, click the time point of a specific slow query log and view its details on the Slow Log Statistics tab.
      View slow query logs
    2. On the Slow Log Statistics tab, click Sample in the Actions column.
      In the Slow Log Sample dialog box, you can view details of the slow query log. Slow query log sample
      Note If the request content of the database is hidden, you can move the pointer over the corresponding content in the Request Content column and view the complete content.

Export slow query logs

You can click Export Slow Log on the Slow Log Statistics tab to save the slow query log information to your computer.