Alibaba Cloud Managed Service for Prometheus allows you to install and configure exporters of the database type, messaging system type, HTTP server type, and other types. Managed Service for Prometheus also provides out-of-the-box dashboards that you can use to monitor your applications.
Quick access for other types of exporters is under development and will be released in the future. If your exporter is not supported by Managed Service for Prometheus, install the exporter, configure service discovery, and then create a dashboard. This topic provides an example on how to install and configure open source exporters that are not supported by Managed Service for Prometheus. In this example, MySQL is used.
For more information about the exporters of open source Prometheus, see Exporters and integrations.
Prerequisites
- A Container Service for Kubernetes (ACK) cluster is created. For more information, see Create an ACK dedicated cluster.
- The ACK cluster is monitored by Managed Service for Prometheus. For more information, see Create a Prometheus instance to monitor an ACK cluster.
- An Elastic Compute Service (ECS) instance is monitored by Managed Service for Prometheus. For more information, see Create a Prometheus instance to monitor an ECS instance.
Procedure
The following figure describes how to use Managed Service for Prometheus to monitor a MySQL database.
Step 1: Deploy an application
To capture MySQL data in an ACK cluster, you must deploy the mysqld-exporter image that is provided by open source Prometheus to the ACK cluster. To deploy the mysqld-exporter image, perform the following operations:
- Log on to the ACK console.
- In the left-side navigation pane, click Clusters.
- On the Clusters page, find the cluster to which you want to deploy the application and click Applications in the Actions column.
- Create a container group. The newly created container group is displayed on the Deployments page.
- Create a Service. The newly created Service is displayed on the Services page.
Step 2: Configure service discovery
To configure service discovery of Managed Service for Prometheus to receive data from the MySQL database, perform the following steps:
- The ACK cluster is monitored by Managed Service for Prometheus. For more information, see Create a Prometheus instance to monitor an ACK cluster.
- An ECS instance is monitored by Managed Service for Prometheus. For more information, see Create a Prometheus instance to monitor an ECS instance.
- Log on to the Prometheus console.
- In the top navigation bar of the Prometheus Service page, select the region where the ACK cluster resides. Find the cluster and click Settings in the Actions column.
- On the Settings page, click the Service Discovery tab. On the Service Discovery tab, click the ServiceMonitor tab.
- On the ServiceMonitor tab, click Add ServiceMonitor.
- In the Add ServiceMonitor dialog box, enter the following code and click OK:
apiVersion: monitoring.coreos.com/v1 kind: ServiceMonitor metadata: # Enter a unique name. name: tomcat-demo # Enter a namespace. namespace: default spec: endpoints: - interval: 30s # Enter the value of the Name field of the Port parameter of the Prometheus exporter in the service.yaml file. port: tomcat-monitor # Enter the path of the Prometheus exporter. path: /metrics namespaceSelector: any: true # The namespace of the NGINX demo application. selector: matchLabels: # Enter the value of the Label field in the service.yaml file to find the service.yaml file. app: tomcat
The configured service discovery task is displayed on the ServiceMonitor tab.
Step 3: Configure a Grafana dashboard
To configure a Grafana dashboard to display data, perform the following steps:
- Go to the homepage of Grafana dashboards.
- In the left-side navigation pane, choose .
- On the Import page, enter 7362 in the Import via grafna.com field and click Load next to the field. 7362 is the ID of the MySQL Grafana template provided by Prometheus.
- On the Import page, perform the following operations and click Import:
- Enter a dashboard name in the Name field.
- Select your ACK cluster from the Folder drop-down list.
- Select your ACK cluster from the prometheus drop-down list.
The following figure shows the configured Grafana dashboard.
Step 4: Create an alert rule
To create an alert rule to monitor a metric, perform the following steps:
- Log on to the Prometheus console.
- In the top navigation bar of the Prometheus Monitoring page, select the region where the monitored Kubernetes cluster resides. Then, click the name of the Kubernetes cluster.
- In the left-side navigation pane, click Alarm configuration.
- On the Alarm configuration page, click Create Alert in the upper-right corner.
- In the Create Alert panel, set the parameters.After you create the alert rule, the Alarm configuration page displays the rule, as shown in the following figure.