You can use CloudLens for RDS to collect the audit log, error log, and slow query log for your ApsaraDB RDS instances. Once the logs are collected, you can audit them, analyze them, and create alerts. You can manually collect logs from a single ApsaraDB RDS instance, or automatically collect logs from multiple existing and future instances that meet specific criteria. This topic describes how to enable log collection by using CloudLens for RDS and related operations.
Prerequisites
-
To manually enable log collection, you must create a Simple Log Service project and logstore in the region where your ApsaraDB RDS instance is located. For more information, see Create a project and a logstore.
-
If you are using a RAM user, you must grant the RAM user the required permissions to use CloudLens for RDS. For more information, see Grant a RAM user permissions to use CloudLens for RDS.
Manually enable log collection
CloudLens for RDS supports collecting the audit log, error log, and slow query log. The procedure is similar for all log types. This section uses audit log collection as an example.
-
Log on to the Simple Log Service console.
-
In the Log Application area, on the Cloud Service Lens tab, click CloudLens for RDS.
-
If you are enabling the feature for the first time, complete the authorization as prompted.
-
A system role named AliyunLogArchiveRole is automatically created. CloudLens for RDS assumes this role to write logs.
-
A service-linked role named AliyunServiceRoleForSLSAudit is automatically created. CloudLens for RDS assumes this role to collect the ApsaraDB RDS audit log. For more information, see Manage the service-linked role AliyunServiceRoleForSLSAudit.
-
-
On the Data Import Management page, on the RDS Cluster Access tab, find the target ApsaraDB RDS instance and click Enable in the Audit Logs column.
-
In the Enable Audit Log Collection dialog box, select the destination project and logstore, and then click Confirm.
After you enable collection, Simple Log Service starts to collect the audit log for the target ApsaraDB RDS instance.
In the cluster list on the RDS Cluster Access page, the status in the Audit Log, Slow Query Log, and Error Log columns for the target instance changes to Collection Enabled.
Configure automatic collection
CloudLens for RDS supports collecting the audit log, error log, and slow query log. The procedure is similar for all log types. This section uses audit log collection as an example.
-
Log on to the Simple Log Service console.
-
In the Log Application area, on the Cloud Service Lens tab, click CloudLens for RDS.
-
On the Data Import Management page, click the Automatic Collection Configuration tab.
-
Turn on the Automatic Collection Configuration switch.
-
Click the icon. Create a Condition, an Automatic Collection Configuration, and an End node in sequence, then click Save in the upper-right corner. The Condition node is optional. The Automatic Collection Configuration and End nodes are required.
Condition
-
Specify collection conditions using properties such as Alibaba Cloud account ID, region, instance ID, instance name, database type, database version, and tag.
-
In the lower-left corner of the dialog box, switch between Advanced Mode and Standard Mode. In Standard Mode, conditions are joined by the AND operator. In Advanced Mode, you can flexibly combine and nest conditions. For more information about the configuration rules, see Matching modes of a condition node.
Automatic collection configuration
Parameter
Description
Automatic collection type
Select an automatic collection type. The following options are available:
-
Custom Destination Logstore: Automatically collects the audit log of ApsaraDB RDS instances that meet the specified conditions to a destination logstore.
If the destination storage (project, logstore) does not exist, it is automatically created.
-
Keep collection settings: When you select Keep collection settings, you do not need to configure the Region, Project, LogStore, or conflict policy parameters.
-
For matching instances where collection is disabled, it will not be automatically enabled.
-
For matching instances where collection is already enabled, their destination logstore remains unchanged.
-
Region
The system automatically selects the region of the target ApsaraDB RDS instance. This setting cannot be modified.
Project
In the region where the ApsaraDB RDS instance resides, the system automatically creates a project named
rds-xxx-${Alibaba Cloud account ID}-${region}. For example, rds-test-117918634953****-cn-hangzhou.Logstore
In the project named
rds-xxx-${Alibaba Cloud account ID}-${region}, the system automatically creates a logstore namedrds_log.Conflict policy
If your configured destination differs from the current one, the system applies the selected policy:
-
Ignore: The current destination is kept.
-
Overwrite: The configured destination is used.
-
-
This example configuration performs the following actions:
-
Delivers the audit log from ApsaraDB RDS for MySQL instances with the tag
env==prodto therds_loglogstore within the project namedrds-prod-${Alibaba Cloud account ID}-${region}. -
Delivers the audit log from ApsaraDB RDS for MySQL instances with the tag
env==testto therds_loglogstore within the project namedrds-test-${Alibaba Cloud account ID}-${region}. -
For other ApsaraDB RDS instances, the destination for the audit log remains unchanged.
The workflow for this automatic collection policy is configured as follows: The first condition node checks if database type is equal to
mysqland tag.env is equal toprod. If the conditions are met, the automatic collection type is set to Custom Destination Logstore, the region is set to Same Region as the Collection Object, the project is set tords-prod-${Alibaba Cloud account ID}-${region}, the logstore is set tords_log, and the conflict policy is set to Overwrite. The second condition node checks if tag.env is equal totest. If this condition is met, a similar configuration is applied, but the project is set tords-test-${Alibaba Cloud account ID}-${region}. The logstore and conflict policy settings are the same. If neither condition is met, the automatic collection type is set to Collection Remains Unchanged.
-
Related operations
|
Actions |
Description |
|
Manage ApsaraDB RDS instances |
On the RDS Cluster Access tab of the Data Import Management page, you can view all ApsaraDB RDS instances under your Alibaba Cloud account, their regions, and collection status. |
|
Disable log collection |
On the RDS Cluster Access tab of the Data Import Management page, find the target ApsaraDB RDS instance and click Close in the column for the corresponding log type. |
|
Query and analyze logs |
You can click Log Query for the target ApsaraDB RDS instance and select the logs. The system then redirects you to the corresponding logstore. There, you can view the raw logs and perform query and analysis operations. For more information, see Query and Analysis Quick Start. |
|
Manage destination projects and logstores |
On the Destination Logstores tab of the Data Import Management page, you can view the projects and logstores used for ApsaraDB RDS logs and modify the data retention period for the destination logstore. |
|
Set up alerts |
On the Anomaly Detection page, you can enable alerts. For more information, see Set up alerts. |
|
View reports |
On the Report Center page, select a destination logstore to view dashboards in the Audit Operations Center, Audit Security Center, or Audit Performance Center. |