This topic describes how to view the storage usage of an ApsaraDB for MongoDB instance by using the storage analysis feature of CloudDBA. The storage analysis feature provides an overview of the storage usage of an instance. The feature also provides information about the storage that is occupied by each object on the instance and allows you to defragment a disk. You can use the storage analysis results to identify and troubleshoot storage exceptions. This ensures the stable performance of the instance.
Prerequisites
The instance is a replica set or sharded cluster instance that runs MongoDB 4.0 or later.
Usage notes
If you want to use the storage analysis feature of CloudDBA as a Resource Access Management (RAM) user, make sure that the RAM user has the AliyunHDMFullAccess or AliyunHDMReadOnlyAccess permission on Database Autonomy Service (DAS). For more information, see How do I use DAS as a RAM user?
View storage overview
Log on to the ApsaraDB for MongoDB console.
In the left-side navigation pane, click Replica set instances or Sharded cluster instance.
In the upper-left corner of the page that appears, select the resource group and region to which the desired instance belongs.
Click the ID of the instance that you want to manage or click Manage in the Actions column.
In the left-side navigation pane of the instance details page, choose .
View the storage analysis results.
View the storage overview of databases
Click the Storage Overview tab to view the following information:
In the Storage section, view the storage overview.
Item
Description
Exception
The number of storage exceptions that are identified in the instance. ApsaraDB for MongoDB can identify the following types of exceptions:
More than 90% of the storage is used.
The available physical storage may be exhausted within seven days.
A single collection contains more than 10 indexes.
Avg Daily Increase in Last Week
The average daily increase of storage usage in the instance over the last seven days.
Formula: (Size of available storage at the time of collection - Size of available storage seven days ago)/7.
NoteThis increase indicates the average daily increase over the last seven days at the time of collection.
This parameter is suitable for scenarios in which the traffic volume remains stable. The value of this parameter becomes inaccurate when storage abruptly changes due to operations such as batch import, deletion of historical data, instance migration, or instance rebuilding.
Available Days of Storage
The number of days during which storage is available in the instance.
Formula: Size of available storage/Average daily increase over the last seven days.
NoteThe value 90+ indicates that the available storage in the instance is sufficient for a long period of time.
This parameter is suitable for scenarios in which the traffic volume remains stable. The value of this parameter becomes inaccurate when storage abruptly changes due to operations such as batch import, deletion of historical data, instance migration, or instance rebuilding.
Used Storage
The amount of storage that is used by the instance and the total storage.
In the Exceptions section, view the information of storage exceptions. You can troubleshoot the exceptions based on the information.
In the Storage Trend section, view the data trends in the last week.
In the Tablespaces section, view the data of collections.
NoteYou can click the name of a collection to view its indexes.
View the storage overview of data space and tablespace
Click the Data Space tab to view the following information:
You can click the name of a data space to view its tablespace information.
You can click the name of a collection to view its indexes.
Defragment a disk
You can only defragment the disk of a hidden node. If you want to defragment a disk of the primary node or a secondary node, you can switch the primary node or the secondary node to the hidden node and then defragment a disk of the new hidden node. Alternatively, you can execute the compact
statement described in Defragment a disk to improve disk usage. For more information about how to perform a primary/secondary switchover, see Primary/Secondary failover.
Log on to the ApsaraDB for MongoDB console.
In the left-side navigation pane, click or .
In the upper-left corner of the page that appears, select the resource group and region to which the desired instance belongs.
Click the ID of the instance that you want to manage or click Manage in the Actions column.
In the left-side navigation pane of the instance details page, choose .
In the Tablespaces section of the page that appears, find the collection that you want to manage. Then, click Recycling in the Fragmentation Rate column.
In the Recycle dialog box, complete related settings.
Automatic defragmentation
If you configure a plan to automatically defragment a disk for the instance, DAS automatically detects the collections of hidden nodes during the specified maintenance window, and then runs the
compact
command on the collections with the sum of index and data storage usage greater than 1 GB and the fragmentation rate greater than 20%.Manual defragmentation
In the Collection with High Fragmentation Rate section, find the collection that you want to manage, and click Recycle in the Actions column. You can defragment a disk by selecting Execute Now or Run in the O & M window.
NoteAfter the operation is complete, the disk is not immediately defragmented. Wait for a few minutes. In practice, the
compact
command continues to run in the background for a period of time to gradually defragment the disk. The defragmentation time depends on the size of the storage to be defragmented. A larger storage requires a longer defragmentation time.We recommend that you do not defragment the disks of a large number of collections at the same time and initiate the next defragmentation task before the current defragmentation task is complete. We recommend that you defragment the disks of up to 10 collections at the same time.
If the collection has a small amount of Recyclable Space, the collection may be defragmented in a less effective manner.
View defragmentation results
After the defragmentation task is complete, click Re-analyze to view the results.
References
The storage analysis feature is supported only for ApsaraDB for MongoDB replica set or sharded cluster instances that run MongoDB 4.0 or later. For more information about how to defragment the disks of ApsaraDB for MongoDB instances that run MongoDB versions earlier than MongoDB 4.0, see Defragment a disk to improve disk usage.
Related tasks
The storage analysis feature of CloudDBA can analyze up to 20,000 tables. If no storage analysis results are displayed, you can check whether the number of tables exceeds 20,000 or whether the used account has the required permissions on the specified tables or databases. If the account does not have the required permissions, you can use one of the following methods to grant your account required permissions on the specified tables or databases:
Grant an existing account required permissions
In the upper section of the instance storage analysis page, click Re-authorize.
Enter the username and password of the account in the Database Account and Password fields.
Click OK.
Grant the current account required permissions by running a command
In the upper section of the instance storage analysis page, click Re-authorize.
Enter the username and password of the account in the Database Account and Password fields.
Click Generate Authorization Command.
Click OK.