To discover and optimize slow SQL queries at the earliest opportunity is essential for routine O&M of databases. Database Autonomy Service (DAS) allows you to configure alert rules for slow SQL queries on a database instance that runs MySQL. If the number of slow SQL queries on the database instance exceeds the specified threshold, the system automatically sends alerts to you. This helps you discover and optimize slow SQL queries at the earliest opportunity.
Prerequisites
A database instance that runs MySQL is created.
The database instance is connected to DAS. For more information, see Connect a database instance to DAS.
Procedure
- Log on to the DAS console.
In the left-side navigation pane, choose Alert Service > Alert Rules.
On the Alert Rules page, click Add Rule in the upper-right corner.
In the Add Rule dialog box, configure the parameters that are described in the following table and click OK.
Parameter
Description
Rule Name
The name of the alert rule. In this example, Alert rule for slow SQL queries is used.
Type
The type of the alert rule. Set this parameter to Threshold Alert.
Description
The conditions that trigger the alert rule. Select Slow SQL Statements of MySQL Instance per Hour from the leftmost drop-down list and set the threshold based on your business requirements.
Alert Interval
The interval at which the system sends alert notifications to you when the alert rule is triggered.
Effective Time
The period of time within which the alert rule takes effect.
Notification Method
The method that is used to send alert notifications. DAS can send alert notifications by text message, webhook, and email.
NoteWebhook supports DingTalk, WeCom, Lark, and Application Real-Time Monitoring Service (ARMS).
After the alert rule is created, choose Alert Service > Alert Templates in the left-side navigation pane.
On the Alert Templates page, click Create Template in the upper-right corner.
In the Create Template dialog box, configure the parameters that are described in the following table and click OK.
Parameter
Description
Template Name
The name of the alert template.
Template Type
The type of the alert template. Set the template type to Database Resource Template.
Select Rule
The alert rule. In the left-side section, select the Alert rule for slow SQL queries alert rule and click the rightwards arrow to add the rule to the right-side section.
Alert Contact
The alert contacts to which alert notifications are sent. You can select contacts from the Existing Contact Group section or create an alert group. For more information, see Manage alert contacts.
Select the alert template that you created, and click Associate in the Actions column to apply the alert template to the database instance.
References
You can enable the autonomy feature for an ApsaraDB RDS for MySQL instance to automatically optimize slow SQL queries on the database instance. This ensures database stability.