arrow

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

image desc

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.

image desc.

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.

image desc

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:

image desc

Go to the logon page of Alibaba Cloud console.

image desc

Fill in the sub-user account and click Next.

image desc

Fill in the sub-user password and click Login.

image desc

After you successfully log on to the console, the following page is displayed.

image desc

3. Create Container cluster

Refer to the following figure and select Container Service to enter the container service console.

image desc

Refer to the figure below to create a cluster first.

image desc

Select the Standard Managed Kubernetes.

image desc

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.

image desc

Start the worker node configuration.

Refer to the figure below and select the instance type of the Worker node.

image desc

The number of worker nodes is set to 3.

image desc

Set password, and click Next.

image desc

Refer to the following figure to set. Click Next.

image desc

Click Create Cluster.

image desc

It takes about 10 minutes to create a cluster. Please wait patiently.

image desc

image desc

4. Enable Prometheus monitoring

Go to the ARMS console, as shown in the following figure.

image desc

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.

image desc

Click Instance Name

image desc

Click on any monitoring Dashboard.

image desc

You can view the detailed monitoring information of Grafana.

image desc

5. RDS environment preparation

5.1 Configure the whitelist

Refer to the figure below and go to the rds console.

image desc

Select the US (Silicon Valley) area, you can see that an rds instance is being created, please wait a few minutes.

image desc

After the creation is complete, click Manage.

image desc

Then, you can see the details of the RDS instance:

image desc

Click Configure Whitelist.

image desc

Click Modify.

image desc

Set according to the figure below and click OK.

image desc

The whitelist is added:

image desc

After the whitelist is modified, the intranet address of the RDS instance can be viewed.

image desc

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.

image desc

Click OK.

image desc

wait for a moment, and then refresh the page to obtain the Internet address:

image desc

5.3 Create a database administrator account

Create an administrator account, as shown in the following figure.

image desc

Create a user, the user information is as follows:

Username: labex

Password: Aliyun-test

image desc

Privileged Account creation takes a few minutes, please wait patiently。

image desc

6. Install Prometheus MySQL monitoring

6.1 Install mysqld-exporter

Go back to the Container Service console and click the cluster name.

image desc

Select Deployments and default namespaces, and click Create from YAML.

image desc

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

image desc

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

image desc

Select Service, copy the following content to the Template, and click Create.

image desc

image desc

6.2 Configure Prometheus monitoring

Go to the ARMS console, as shown in the following figure, and click Settings.

image desc

As shown in the following figure, select Service Discovery and click Add ServiceMonitor.

image desc

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

image desc

Add complete.

image desc

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.

image desc

Click Import, as shown in the following figure.

image desc

Copy the contents of the Dashboard configuration file you just downloaded to the page and click Load.

image desc

As shown in the following figure, set the name of the Dashboard, select the Folder and telegraf, and click Import.

image desc

You can see the monitoring data of Mysql.

image desc

<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:

image descimage desc

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.