Use Alibaba Cloud Prometheus To Monitor MySQL Databases
1. Experiment
1.1 Knowledge points
In the experiment, Alibaba Cloud Prometheus monitoring service is used. The experiment describes how to use Prometheus to capture MySQL monitoring data and use Grafana to display MySQL monitoring data. Prometheus is an open-source system monitoring and alarm framework. Alibaba Cloud Prometheus monitoring is fully connected to the open-source Prometheus ecosystem. It supports a variety of component monitoring and provides a variety of out-of-the-box monitoring dashboard, and provides fully managed Prometheus services.
1.2 Experiment process
- Create Container cluster
- Enable Prometheus monitoring
- RDS environment preparation
- Install Prometheus Mysql monitoring
- Create Grafana dashboard
1.3 Scene architecture diagram
1.4 Cloud resources required
- RDS
- Container Service
- Prometheus
1.5 Prerequisites
- Before starting the experiment, please confirm that the previous experiment has been closed normally and exited.
2. Start the experiment environment
Click Start Lab in the upper right corner of the page to start the experiment.
.
After the experiment environment is successfully started, the system has deployed resources required by this experiment in the background, For example the ECS instance, RDS instance, Server Load Balancer instance, and OSS bucket. An account consisting of the username and password for logging on to the Web console of Alibaba Cloud is also provided.
After the experiment environment is started and related resources are properly deployed, the experiment starts a countdown. You have an hour to perform experimental operations. After the countdown ends, the experiment stops, and related resources are released. During the experiment, pay attention to the remaining time and arrange your time wisely. Next, use the username and password provided by the system to log on to the Web console of Alibaba Cloud and view related resources:
Go to the logon page of Alibaba Cloud console.
Fill in the sub-user account and click Next.
Fill in the sub-user password and click Login.
After you successfully log on to the console, the following page is displayed.
3. Create Container cluster
Refer to the following figure and select Container Service to enter the container service console.
Refer to the figure below to create a cluster first.
Select the Standard Managed Kubernetes.
Refer to the figure below, set the cluster name, select the US (Silicon Valley) area, and check the VPC network and switch to which it belongs. Click Next.
Start the worker node configuration.
Refer to the figure below and select the instance type of the Worker node.
The number of worker nodes is set to 3.
Set password, and click Next.
Refer to the following figure to set. Click Next.
Click Create Cluster.
It takes about 10 minutes to create a cluster. Please wait patiently.
4. Enable Prometheus monitoring
Go to the ARMS console, as shown in the following figure.
Select the Silicon Valley area, Prometheus monitoring.You can see that the container cluster just created has been connected to the monitoring. If you do not see it, please wait for about 3 minutes.
Click Instance Name
Click on any monitoring Dashboard.
You can view the detailed monitoring information of Grafana.
5. RDS environment preparation
Refer to the figure below and go to the rds console.
Select the US (Silicon Valley) area, you can see that an rds instance is being created, please wait a few minutes.
After the creation is complete, click Manage.
Then, you can see the details of the RDS instance:
Click Configure Whitelist.
Click Modify.
Set according to the figure below and click OK.
The whitelist is added:
After the whitelist is modified, the intranet address of the RDS instance can be viewed.
5.2 Request an Internet address
After setting the whitelist, you can obtain the intranet address. However, an Internet address also needs to be requested to manage RDS.
Click OK.
wait for a moment, and then refresh the page to obtain the Internet address:
5.3 Create a database administrator account
Create an administrator account, as shown in the following figure.
Create a user, the user information is as follows:
Username: labex
Password: Aliyun-test
Privileged Account creation takes a few minutes, please wait patiently。
6. Install Prometheus MySQL monitoring
6.1 Install mysqld-exporter
Go back to the Container Service console and click the cluster name.
Select Deployments and default namespaces, and click Create from YAML.
Select Custom, copy the following content to the Template, and click Create.Please replace the YOUR-RDS-USER, YOUR-RDS-PASSWORD, and YOUR-RDS-PUBLIC-DOMAIN with the administrator account, password and public network access address of your RDS instance
apiVersion: apps/v1
kind: Deployment
metadata:
name: mysqld-exporter
spec:
replicas: 1
selector:
matchLabels:
app: mysqld-exporter
template:
metadata:
labels:
app: mysqld-exporter
spec:
containers:
- name: mysqld-exporter
imagePullPolicy: Always
env:
- name: DATA_SOURCE_NAME
value: "YOUR-RDS-USER:YOUR-RDS-PASSWORD@(YOUR-RDS-PUBLIC-DOMAIN:3306)/"
image: prom/mysqld-exporter
ports:
- containerPort: 9104
name: mysqld-exporter
Select Service, copy the following content to the Template, and click Create.
apiVersion: v1
kind: Service
metadata:
labels:
app: mysqld-exporter
name: mysqld-exporter
spec:
ports:
- name: mysqld-exporter
port: 9104
protocol: TCP
targetPort: 9104
type: NodePort
selector:
app: mysqld-exporter
Select Service, copy the following content to the Template, and click Create.
Go to the ARMS console, as shown in the following figure, and click Settings.
As shown in the following figure, select Service Discovery and click Add ServiceMonitor.
Make the original default content clear, copy the following content to the pop-up box, and click OK.
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
labels:
app: mysqld-exporter
release: p
name: mysqld-exporter
namespace: default
spec:
endpoints:
- interval: 30s
port: mysqld-exporter
path: /metrics
namespaceSelector:
any: true
selector:
matchLabels:
app: mysqld-exporter
Add complete.
7. Create Grafana dashboard
Enter the following link in the browser to download the custom Mysql Dashboard configuration file.
http://labex-ali-data.oss-us-west-1.aliyuncs.com/Prometheus/Mysql-Grafana-Dashboard.json
Click the Dashboard of Prometheus, as shown in the following figure.
Click Import, as shown in the following figure.
Copy the contents of the Dashboard configuration file you just downloaded to the page and click Load.
As shown in the following figure, set the name of the Dashboard, select the Folder and telegraf, and click Import.
You can see the monitoring data of Mysql.
<font color='red'>Users can cut off the above result picture when they are doing the experiment and send it to the teacher, indicating that the current experiment has been completed.</font>
Reminder:
Before you leave this lab, remember to log out your Alibaba RAM account before you click the ‘stop’ button of your lab. Otherwise you’ll encounter some issues when opening a new lab session in the same browser:
8. Experiment summary
The experiment describes how to use Prometheus to capture MySQL monitoring data and use Grafana to display MySQL monitoring data. Compared with open-source Prometheus monitoring, the overall structure of Alibaba Cloud Prometheus monitoring is lighter. You do not need to build the Prometheus monitoring system. You only need to install the Prometheus monitoring system to start monitoring services.