By using the default service discoveries, custom service discoveries, ServiceMonitor, and PodMonitor of Alibaba Cloud Managed Service for Prometheus, you can optimize the monitoring scope of your Container Service for Kubernetes (ACK) cluster, ensure that the required metric data is collected, and efficiently monitor and analyze different services and pods.
Using service discoveries to collect metrics may incur fees. For information about billing, see Billing (new) and Billing (old).
Prerequisites
A Prometheus instance for Container Service is created. For more information, see Monitor an ACK cluster.
Limits
The ACK cluster must be monitored by a Prometheus instance for Container Service.
Procedure
-
Log on to the ARMS console.
-
In the left navigation pane, choose .
-
Click the name of the Prometheus instance.
Manage default service discoveries
Enable and view default service discoveries
When you connect an ACK cluster to Managed Service for Prometheus, the default service discoveries are disabled by default. You need to manually enable them. Perform the following steps:
-
In the left-side navigation pane of the Prometheus instance details page, click Service Discovery.
-
On the Service Discovery page, click the Configure tab.
-
On the Default Service Discovery tab, find the pod that you want to manage and turn on the switch in the Actions column.
NoteThe metrics of pods in all namespaces of the ACK cluster are collected. If a pod contains the following annotations, the default service discoveries collect the metrics of the pod and incur fees:
-
prometheus.io/path: /metrics -
prometheus.io/port: "9104" -
prometheus.io/scrape: "true"
-
-
Then, you can view the default service discoveries provided by Managed Service for Prometheus.
What to do next
On the Default Service Discovery tab, you can perform the following operations:
-
View details of a default service discovery: Click Details in the Actions column to view the YAML configuration file.
-
Disable a default service discovery: Turn off the switch in the Actions column. After you disable a default service discovery, the collection of metric data is stopped and no fees are incurred.
Manage custom ServiceMonitor configurations
You can manually add a ServiceMonitor configuration file to specify the services that you want to monitor, and the metrics that you want to collect.
Create a ServiceMonitor configuration
You can create a ServiceMonitor configuration if you want to monitor the business data of applications in an ACK cluster, such as order information.
-
In the left-side navigation pane, click Service Discovery. Then, click the Configure tab.
-
Click the ServiceMonitor tab. Then, click Add ServiceMonitor.
-
In the dialog box that appears, specify the configuration and click OK.
Sample configuration:
apiVersion: monitoring.coreos.com/v1 kind: ServiceMonitor metadata: name: tomcat-demo # A unique name of the ServiceMonitor. namespace: default # The namespace of the ServiceMonitor. spec: endpoints: - interval: 30s port: tomcat-monitor # The value of the Name field of the port corresponding to the Prometheus exporter in the service.yaml file. path: /metrics # The path of the Prometheus exporter. namespaceSelector: # The namespace of the NGINX demo application. any: true selector: matchLabels: # The value of the Label field in the service.yaml file that can be used to find the service.yaml file. app: tomcatAfter the configuration is specified, the ServiceMonitor appears on the ServiceMonitor tab.
If automatic synchronization of ServiceMonitor configurations in a cluster is enabled, the system discovers ServiceMonitor configurations in the cluster and collects data by default. For more information, see Synchronize the ServiceMonitor and PodMonitor in a cluster.

What to do next
On the ServiceMonitor tab, you can perform the following operations:
-
Modify a ServiceMonitor configuration: Click Edit in the Actions column.
-
Delete a ServiceMonitor configuration: Click Delete in the Actions column. If you delete a ServiceMonitor configuration, the metric data is no longer collected and billed.
-
Disable a ServiceMonitor configuration: Turn off the switch in the Actions column. You can also click Disable all to disable all the ServiceMonitor configurations that you created. After you disable a ServiceMonitor configuration, the collection of metric data is stopped and no fees are incurred.
-
Enable a ServiceMonitor configuration: Turn on the switch in the Actions column.
ImportantFor information about how to identify why a ServiceMonitor configuration fails to collect the expected metric data, see Why does the ServiceMonitor or PodMonitor that I configured not take effect?
Manage PodMonitor configurations
You can manually add a PodMonitor configuration file to specify the services that you want to monitor, and the metrics that you want to collect.
Create a PodMonitor configuration
-
In the left-side navigation pane, click Service Discovery. Then, click the Configure tab.
-
Click the PodMonitor tab. Then, click Add PodMonitor.
-
In the dialog box that appears, specify the configuration and click OK.
Sample configuration:
apiVersion: monitoring.coreos.com/v1 kind: PodMonitor metadata: # A unique name. name: podmonitor-demo # A namespace. namespace: default #https://github.com/prometheus-operator/prometheus-operator/blob/master/Documentation/api.md#podmonitorspec spec: selector: matchLabels: # The value of the Label field in the pod.yaml file that can be used to find the service.yaml file. app: nginx2-exporter namespaceSelector: # https://github.com/prometheus-operator/prometheus-operator/blob/master/Documentation/api.md#namespaceselector any: true podMetricsEndpoints: - interval: 30s # The value of the Name field of the Port parameter of the Prometheus exporter in the pod.yaml file. port: tomcat-monitor # The path of the Prometheus exporter. path: /metricsAfter the configuration is specified, the PodMonitor appears on the PodMonitor tab.
If automatic synchronization of PodMonitor configurations in a cluster is enabled, the system discovers PodMonitor configurations in the cluster and collects data by default. For more information, see Synchronize the ServiceMonitor and PodMonitor in a cluster.

What to do next
On the PodMonitor tab, you can perform the following operations:
-
Modify a PodMonitor configuration: Click Edit in the Actions column.
-
Delete a PodMonitor configuration: Click Delete in the Actions column. If you delete a PodMonitor configuration, the metric data is no longer collected and billed.
-
Disable a PodMonitor configuration: Turn off the switch in the Actions column. You can also click Disable all to disable all the PodMonitor configurations that you created. After you disable a PodMonitor configuration, the collection of metric data is stopped and no fees are incurred.
-
Enable a PodMonitor configuration: Turn on the switch in the Actions column.
ImportantFor information about how to identify why a PodMonitor configuration fails to collect the expected metric data, see Why does the ServiceMonitor or PodMonitor that I configured not take effect?
Manage custom service discoveries
You can create custom service discoveries and collect metrics based on your business requirements.
Create a custom service discovery
-
In the left-side navigation pane, click Service Discovery. Then, click the Configure tab.
-
Click the Custom Service Discovery tab, and then click Add.
-
In the dialog box that appears, enter the settings and click Save.
Sample settings:
#just support scrape_configs configure,Configuring Multiple Jobs,yaml uses the list format.other configure can by setting prometheus.yaml - job_name: prometheus metrics_path: /metric static_configs: - targets: - 127.0.0.1:9090 - job_name: grafana_exporter scrape_interval: 30s scrape_timeout: 30s metrics_path: /metric static_configs: - targets: - 127.0.0.1:3000After you complete the settings, the service discovery is displayed on the Custom Service Discovery tab.

What to do next
On the Custom Service Discovery tab, you can perform the following operations:
-
Modify a service discovery: Click Edit in the Actions column.
-
Delete a service discovery: Click Delete in the Actions column. If you delete a service discovery, the metric data is no longer collected and billed.
References
-
After you enable the preceding service discoveries, ServiceMonitor configurations, and PodMonitor configurations, you may need to view the collected metrics. For more information, see Configure metrics.
-
For information about the billing caused by metric collection, see Why am I charged additional fees when I use Managed Service for Prometheus?
-
For information about how to create a service discoveries by using ServiceMonitor, see Use ServiceMonitor configurations to discover and monitor Services.