All Products
Search
Document Center

Managed Service for Prometheus:Use Managed Service for Prometheus to monitor MySQL databases

Last Updated:Apr 29, 2024

This topic describes how to use Alibaba Cloud Managed Service for Prometheus to monitor MySQL databases.

Prerequisites

Step 1: Install and configure a MySQL exporter

  1. Log on to the Managed Service for Prometheus console.

  2. In the left-side navigation pane, click Instances.

  3. Click the name of the Prometheus instance instance that you want to manage to go to the Integration Center page.

  4. Install or add the MySQL component.

    • If you install the MySQL component for the first time, perform the following operation:

      In the Not Installed section of the Integration Center page, find the MySQL component and click Install.

    • If you have installed the MySQL component, add the component again:

      In the Installed section of the Integration Center page, click Add next to MySQL.

  5. On the Settings tab in the STEP2 section, configure the parameters and click OK. The following table describes the parameters.

    Parameter

    Description

    Component Name

    The unique name of the MySQL exporter. The name must meet the following requirements:

    • It can contain only lowercase letters, digits, and hyphens (-), and cannot start or end with a hyphen (-).

    • It must be unique.

    Note

    If you do not specify this parameter, the system uses the default name, which consists of the exporter type and a numeric suffix.

    MySQL URL

    The URL that is used to access the MySQL database.

    Note

    The URL of the MySQL database that is deployed in ACK, ECS, or ApsaraDB RDS is automatically displayed in the drop-down list.

    MySQL Port

    The port number of the MySQL database. Example: 3306.

    Username

    The username and password of the MySQL database.

    Important

    We recommend that you do not use an administrator account to avoid data breach risks. Create a MySQL account for mysqld_exporter and grant minimum permissions to the account. For more information, see Permissions required for mysqld_exporter to access a MySQL database.

    Password

    Note

    You can view the monitoring metrics on the Metrics tab in the STEP2 section.

    You can also configure the resource quotas for the exporter in the Advanced Settings: Exporter Resource Limits section. The default value of the CPU (Cores) parameter is 100m, and the default value of the memory parameter is 50Mi.

    The installed components are displayed in the Installed section of the Integration Center page. Click the component. In the panel that appears, you can view information such as targets, metrics, dashboard, alerts, service discovery configurations, and exporters. For more information, see Integration center.

Step 2: Configure alert rules for the MySQL exporter

On the Integration Center page in the Application Real-time Monitoring Service (ARMS) console, click the MySQL exporter in the Installed section. In the panel that appears, click the Alerts tab to view the alert rules for MySQL databases.

Managed Service for Prometheus provides multiple default alert rules based on key MySQL metrics. You can add alert rules based on your business requirements. For information about how to add alert rules, see Create an alert rule for a Prometheus instance.
Note

Step 3: View the dashboards for the MySQL database

You can use the dashboards to view monitoring data, such as the service availability, database queries, network traffic, connections, and memory usage. To find the dashboards, you can perform the following steps:

  1. Log on to the Managed Service for Prometheus console.

  2. In the left-side navigation pane, click Instances.

  3. Click the name of the Prometheus instance instance that you want to manage to go to the Integration Center page.

  4. Click the MySQL exporter in the Installed section. In the panel that appears, click the Dashboards tab and then click the thumbnail of the Grafana dashboard that you want to view. You can view the following dashboards:
    • Service availability, queries per second (QPS), and database connections fl
    • Database queries ze
    • Traffic and memory usage sh
    • File monitoring data al

Key metrics

TypeMetricDescription
Availabilitymysql_upIndicates whether the MySQL database is available.
mysql_global_status_uptimeIndicates the running duration of the MySQL database. You can add an alert rule based on this metric to identify MySQL databases whose running duration is less than 30 minutes.
Database connectionsmysql_global_status_connection_errors_totalIndicates connection errors that are one of the major database errors. You can use this metric to view the information about a specific error and the number of connection errors.
mysql_global_status_threads_connectedIndicates the number of threads on which connections to the MySQL database are established.
mysql_global_status_threads_runningIndicates the number of threads on which the requests to connect to the MySQL database are sent but do not succeed yet.
mysql_global_status_max_used_connectionsIndicates the maximum number of connections to the MySQL database.
mysql_global_variables_max_connectionsIndicates the upper limit on the connections to the MySQL database. When the number of connections reaches the upper limit, requests to establish connections are denied.
mysql_global_status_aborted_connectsIndicates the failed connection attempts.
mysql_global_status_aborted_clientsIndicates the connections that timed out.
Queriesmysql_global_status_slow_queriesIndicates the slow queries of the MySQL database.
mysql_global_status_queriesIndicates the QPS of the MySQL database.
Network trafficmysql_global_status_bytes_receivedIndicates inbound traffic.
mysql_global_status_bytes_sentIndicates outbound traffic.
File monitoring datamysql_global_status_opened_filesIndicates the files that are being opened.
mysql_global_status_open_filesIndicates the files that are opened in the MySQL database.
mysql_global_variables_open_files_limitIndicates the files that can be opened.
mysql_global_status_innodb_num_open_filesIndicates the files that are opened by InnoDB.

Use Managed Service for Prometheus to view monitoring data and configure alert rules

If you use a self-managed Managed Service for Prometheus to monitor a MySQL database, you must perform the following complex operations: install the MySQL exporter, enter information about the connection to the MySQL database, configure service discovery, and build dashboards. Alibaba Cloud Managed Service for Prometheus provides the built-in MySQL exporter and out-of-the-box dashboards and alert configurations in the visualized console. This simplifies service deployment and reduces workloads.

Alibaba Cloud Managed Service for Prometheus creates default alert rules for MySQL databases based on practices. You can use the default alert rules to quickly configure your dashboards and alerting system. Alibaba Cloud Managed Service for Prometheus provides the default alert rules based on the following metrics:
  • MySQL database availability: If the metric value is 0, the MySQL database is unavailable. If the metric value is 1, the MySQL database is running as expected. You can replace the ${instance} variable with the MySQL database that you want to monitor.
    mysql_up{${instance}} != 1
  • Running duration of the MySQL database: Managed Service for Prometheus provides a default alert threshold of 30 minutes. You can change the threshold based on your business requirements.
    mysql_global_status_uptime{${instance}} < 1800
  • Slow queries in the MySQL database: You can use this metric to identify SQL statements that can be improved in the database.
    rate(mysql_global_status_slow_queries{${instance}}[5m]) > 0
  • Connection errors of the MySQL database: Connection errors are one of the major database errors. Managed Service for Prometheus provides an alert rule based on this metric. When an alert is generated, you can receive a notification that contains the error type, QPS, and other error details.
    rate(mysql_global_status_connection_errors_total{${instance}}[5m]) > 0
  • Connection usage of the MySQL database: Most connection errors are caused by insufficient number of connections. You can troubleshoot connection errors based on this metric.
    100 * mysql_global_status_threads_connected{${instance}} 
          / mysql_global_variables_max_connections{${instance}} > 90
    When the connection usage reaches the upper limit, the MySQL database denies connection requests. To resolve this issue, you can increase the upper limit. Before you increase the upper limit on connections, you must run the following command to check the upper limit on the files that can be opened.
    mysql_global_variables_open_files_limit - mysql_global_variables_innodb_open_files
  • Log wait time of the MySQL database: You can specify a period of time during which a log write must wait for the undo log to be flushed.
    rate(mysql_global_status_innodb_log_waits{${instance}}[5m])