ARMS Prometheus monitoring allows you to monitor MySQL databases by capturing data from the databases and presenting the captured data on the ARMS Prometheus Grafana dashboard.

Background information

The following figure shows the workflow.

How It Works

Step 1: Capture data from a MySQL database by using an external application

Deploy the mysqld-exporter image provided by Prometheus to a Container Service for Kubernetes (ACK) cluster to capture MySQL data.

  1. Log on to the Alibaba Cloud Container Service for Kubernetes console.
  2. In the left-side navigation pane, click Clusters. On the Clusters page, click Applications in the Actions column corresponding to the cluster.
    K8s Cluster Console Button
  3. On the Workloads page, click the Deployments tab. On the Deployments tab, click Create from Template.
  4. On the Create from Template tab, select Custom from the Sample Template drop-down list. Enter the following text into the Template text editor and click Create to deploy the mysqld-exporter application to the ACK cluster.
    Note Replace the values of <yourMySQLUsername>, <yourMySQLPassword>, <IP>, and <port> with the corresponding values of the MySQL database.
    apiVersion: extensions/v1beta1
    kind: Deployment
      name: mysqld-exporter
      replicas: 1
            app: mysqld-exporter
          - name: mysqld-exporter
            imagePullPolicy: Always
              - name: DATA_SOURCE_NAME
                value: "<yourMySQLUsername>:<yourMySQLPassword>@(<IP>:<port>)/"
            image: prom/mysqld-exporter
            - containerPort: 9104
              name: mysqld-exporter
  5. In the left-side navigation pane, choose Services and Ingresses > Services. On the Services page, click Create Resources in YAML.
  6. On the Workloads tab, enter the following text in the Template text editor and click Create:
    apiVersion: v1
    kind: Service
        app: mysqld-exporter
      name: mysqld-exporter
      - name: mysqld-exporter
        port: 9104
        protocol: TCP
        targetPort: 9104
      type: NodePort
        app: mysqld-exporter

Step 2: Configure ARMS Prometheus Monitoring to receive data from the MySQL database

  1. Log on to the Alibaba Cloud Container Service for Kubernetes console.
  2. Enable ARMS Prometheus Monitoring for the ACK cluster. For more information, see Get started with Prometheus Service.
  3. Log on to the ARMS console.
  4. In the left-side navigation pane, click Prometheus Monitoring.
  5. In the upper-left corner of the Prometheus Monitoring page, select the region where your ACK cluster is deployed. Find the cluster and click Settings in the Actions column.
  6. On the Settings page, click the Service Discovery tab. On the Service Discovery tab, click Add ServiceMonitor. In the Add ServiceMonitor dialog box, enter the following content and click OK:
    kind: ServiceMonitor
        app: mysqld-exporter
        release: p
      # Enter a unique name.
      name: mysqld-exporter
      # Enter the desired namespace.
      namespace: default
      - interval: 30s
        # The Mysqld Grafana template ID is 7362.
        # Enter the value of the Name field for Port of Prometheus Exporter in the service.yaml file.
        port: mysqld-exporter
        # Enter the value of the Path field for Prometheus Exporter.
        path: /metrics
        any: true
        # Demo namespace:
          app: mysqld-exporter

Step 3: Present data of the MySQL database on the Grafana dashboard

Import the Grafana dashboard template and specify the ACK cluster where the Prometheus data source is located.

  1. Go to Prometheus Grafana.
  2. In the left-side navigation pane, choose + > Import, enter 7362 in the Import via field, and then click Load.
    Import Grafana Dashboard
  3. On the Import page, configure the following parameters and click Import.
    Import Grafana Dashboard with Options
    1. Enter a custom dashboard name in the Name field.
    2. Select your ACK cluster from the Folder drop-down list.
    3. Select your ACK cluster from the prometheus drop-down list.
    After the parameters are configured, the Prometheus Grafana MySQL dashboard is displayed as shown in the following figure.ARMS Prometheus Grafana MySQL

Step 4: Create a Prometheus Monitoring alert

  1. Log on to the ARMS console.
  2. In the left-side navigation pane, click Prometheus Monitoring.
  3. In the top navigation bar, select a region. Then, click the name of the required Kubernetes cluster.
  4. In the left-side navigation pane, choose Alarm configuration beta. Then, click Create Alert in the upper-right corner.
  5. In the Create Alert dialog box, configure the following parameters, and then click OK.
    Note The Time parameter is not supported.
    1. Enter a name in the Rule Name field. Example: alerts for inbound traffic.
    2. Enter an expression that uses a PromQL statement. Example: (sum(rate(kube_state_metrics_list_total{job="kube-state-metrics",result="error"}[5m])) / sum(rate(kube_state_metrics_list_total{job="kube-state-metrics"}[5m]))) > 0.01.
      Notice An error may be reported if a PromQL statement contains a dollar sign ($). You must remove the equal sign (=) and the parameters on both sides of the equal sign (=) from the statement that contains the dollar sign ($). For example, change sum (rate (container_network_receive_bytes_total{instance=~"^$HostIp.*"}[1m])) to sum (rate (container_network_receive_bytes_total[1m])).
    3. In the Labels section, click Create Tag to specify alert tags. The specified tags can be used as options for a dispatch rule.
    4. In the Annotations section, specify a template for alert messages. Click Create Annotation. Set Key to message and Value to {{variable name}} alert message. The specified annotation is in the format of message:{{variable name}} alert notification. Example: message:{{$labels.pod_name}} restart.

      You can customize a variable name or select an existing tag as the variable name. Existing tags:

      • The tags that are carried in the metrics of an alert rule expression.
      • The tags that are created when you create an alert rule. For more information, see Create an alert.
      • The default tags provided by ARMS. The following table describes the default tags.
        Tag Description
        alertname The name of the alert. The format is <Alert name>_<Cluster name>.
        _aliyun_arms_alert_level The level of the alert.
        _aliyun_arms_alert_type The type of the alert.
        _aliyun_arms_alert_rule_id The ID of the alert rule.
        _aliyun_arms_region_id The ID of the region.
        _aliyun_arms_userid The ID of the user.
        _aliyun_arms_involvedObject_type The subtype of the associated object, for example, ManagedKubernetes or ServerlessKubernetes.
        _aliyun_arms_involvedObject_kind The type of the associated object, for example, app or cluster.
        _aliyun_arms_involvedObject_id The ID of the associated object.
        _aliyun_arms_involvedObject_name The name of the associated object.
    Prometheus-Create alarm

What to do next

After the ARMS Prometheus Grafana MySQL dashboard is configured, you can view metrics of Prometheus Monitoring and customize the dashboard. For more information, see the following topics.