When you deploy application instances in a VKE cluster, you can use cloud-native observability to monitor the application instances. This topic describes how to monitor MySQL instances in clusters.
Background information
MySQL is a commonly used relational database. In Kubernetes, you can use the open source mysqld-exporter to monitor the running status of MySQL instances deployed in clusters.
Prerequisites
Procedure
Step 1: Grant permissions on the database
mysqld-exporter performs monitoring by querying status data in the target database. Therefore, you need to grant the required permissions on the corresponding database instance. You can run the following command to grant permissions to a user.
tip
We recommend that you specify the maximum number of connections for the user to prevent the database from being affected by monitoring data collection. However, this configuration may not take effect in all database versions. For example, MariaDB v10.1 does not allow you to specify the maximum number of connections.
Step 2: Create a MySQL connection string Secret
- In the left navigation bar, click Cluster.
- On the Cluster page, click the name of the target cluster to go to the cluster management page.
- In the left navigation bar, click Configurations > Secret. On the Secret page, click Create with Yaml to configure a Secret.
Step 3: Deploy mysql-exporter
In the left navigation bar, click Workload > Deployment. Click Create with Yaml to deploy mysql-exporter.
Step 4: Configure service discovery
- In the left navigation bar, click Workload > Resource Explorer. Click Create with Yaml to configure a collection rule by using a PodMonitor.
- Select Custom from the Type drop-down menu.
- Edit the configurations in the Yaml box.
Validating results
- Run the following command to configure Grafana port mapping.
- Open a browser in the local environment (Linux/Mac), enter localhost:3000 in the address bar to go to the Grafana login page, and then log in to Grafana by using the default username admin and password admin.
- Create a MySQL dashboard to view MySQL metrics.