You can use the default service discovery, ServiceMonitor, PodMonitor, and custom service discovery features of Alibaba Cloud Managed Service for Prometheus to refine the monitoring scope of your Kubernetes clusters. These features help you collect the specific metric data required to monitor and analyze various services and pods.
Using service discovery to collect metrics may incur charges. For more information about billing, see Product Billing and Product Billing (Old Version).
Prerequisites
A Prometheus instance for Container Service is created. For more information, see Monitor an ACK cluster.
Limitations
This feature is available only for Prometheus instances that monitor ACK clusters.
Procedure
-
Log on to the ARMS console.
-
In the left navigation pane, choose .
-
Click the name of the target Prometheus instance.
Manage default service discovery
Enable and view default service discovery
The default service discovery feature is disabled by default. To enable it:
-
On the instance details page, click Service Discovery in the left-side navigation pane.
-
On the Service Discovery page, click the Configurations tab.
-
On the Default Service Discovery tab, find the target pod, and turn on the switch in the Operation column.
NoteIf a pod has the following annotations, default service discovery automatically collects its metrics, which incurs corresponding fees.
-
prometheus.io/path: /metrics -
prometheus.io/port: "9104" -
prometheus.io/scrape: "true"
-
-
After you enable default service discovery, you can view the instance's default scrape tasks.
More operations
On the Default Service Discovery tab, you can perform the following operations:
-
View details: To view the YAML configuration for a default service discovery, click Details in the Operation column.
-
Disable default service discovery: Turn off the switch in the Operation column. Disabling it stops metric data collection and associated billing.
Manage ServiceMonitors
Add a ServiceMonitor configuration file to define which services to monitor and which metrics to collect.
Add a ServiceMonitor
A typical use case for a ServiceMonitor is to monitor business data from applications in a Kubernetes cluster, such as order information.
-
In the left-side navigation pane, click Service Discovery and then click the Configurations tab.
-
Click the ServiceMonitor tab and then click Add ServiceMonitor in the upper-right corner.
-
In the dialog box, enter the configuration and click OK.
Sample configuration:
apiVersion: monitoring.coreos.com/v1 kind: ServiceMonitor metadata: name: tomcat-demo # Enter a unique name. namespace: default # Enter the target namespace. spec: endpoints: - interval: 30s port: tomcat-monitor # Enter the value of the Name field of the port for the Prometheus exporter in the service.yaml file. path: /metrics # Enter the path of the Prometheus exporter. namespaceSelector: # The namespace of the Nginx demo application. any: true selector: matchLabels: # Enter the value of the 'app' label in the service.yaml file to locate the target service. app: tomcatAfter the configuration is complete, the new ServiceMonitor appears on the ServiceMonitor tab.
If you enable automatic synchronization of ServiceMonitors in the cluster, the system automatically discovers them and collects their data. For more information, see Synchronize ServiceMonitors in a cluster.

More operations
On the ServiceMonitor tab, you can perform the following operations:
-
Edit a ServiceMonitor: To modify a custom ServiceMonitor, click Edit in the Operation column.
-
Delete a ServiceMonitor: To delete a custom ServiceMonitor, click Delete in the Operation column. Deleting a ServiceMonitor stops metric data collection and associated billing.
-
Disable a ServiceMonitor: Turn off the switch in the Operation column. You can also click Disable All in the upper-right corner to disable all added ServiceMonitors at once. Disabling a ServiceMonitor stops metric data collection and associated billing.
-
Enable a ServiceMonitor: Turn on the switch in the Operation column.
ImportantIf metric data is not collected after you enable a ServiceMonitor, see the linked article to troubleshoot the issue. For more information, see Why is my configured ServiceMonitor or PodMonitor not working?.
Manage PodMonitors
Add a PodMonitor configuration file to define the pods to monitor and the metrics to collect.
Add a PodMonitor
-
In the left-side navigation pane, click Service Discovery and then click the Configurations tab.
-
Click the PodMonitor tab and then click Add PodMonitor in the upper-right corner.
-
In the dialog box, enter the configuration and click OK.
Sample configuration:
apiVersion: monitoring.coreos.com/v1 kind: PodMonitor metadata: # Enter a unique name. name: podmonitor-demo # Enter the target namespace. namespace: default # For more information, see https://github.com/prometheus-operator/prometheus-operator/blob/master/Documentation/api.md#podmonitorspec spec: selector: matchLabels: # Enter the value of the 'app' label in the pod.yaml file to locate the target pod. app: nginx2-exporter namespaceSelector: # For more information, see https://github.com/prometheus-operator/prometheus-operator/blob/master/Documentation/api.md#namespaceselector any: true podMetricsEndpoints: - interval: 30s # Enter the value of the Name field of the port for the Prometheus exporter in the pod.yaml file. port: tomcat-monitor # Enter the path of the Prometheus exporter. path: /metricsAfter the configuration is complete, the new PodMonitor appears on the PodMonitor tab.
If you enable automatic synchronization of PodMonitors in the cluster, the system automatically discovers them and collects their data. For more information, see Synchronize PodMonitors in a cluster.

More operations
On the PodMonitor tab, you can perform the following operations:
-
Edit a PodMonitor: To modify a custom PodMonitor, click Edit in the Operation column.
-
Delete a PodMonitor: To delete a custom PodMonitor, click Delete in the Operation column. Deleting a PodMonitor stops metric data collection and associated billing.
-
Disable a PodMonitor: Turn off the switch in the Operation column. You can also click Disable All in the upper-right corner to disable all added PodMonitors at once. Disabling a PodMonitor stops metric data collection and associated billing.
-
Enable a PodMonitor: Turn on the switch in the Operation column.
ImportantIf metric data is not collected after you enable a PodMonitor, see the linked article to troubleshoot the issue. For more information, see Why is my configured ServiceMonitor or PodMonitor not working?.
Manage custom service discovery
You can also define custom scrape jobs to collect metrics based on your business requirements.
Add a custom service discovery
-
In the left-side navigation pane, click Service Discovery and then click the Configurations tab.
-
Click the Custom Service Discovery tab and then click Add in the upper-right corner.
-
In the dialog box, enter the configuration and click Save.
Sample configuration:
# Only scrape_configs are supported. To configure multiple jobs, use the list format in YAML. # Other configurations can be set in the prometheus.yaml file. - 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 the configuration is complete, the new service discovery appears on the Custom Service Discovery tab.

More operations
On the Custom Service Discovery tab, you can perform the following operations:
-
Edit a service discovery: To modify a custom service discovery, click Edit in the Operation column.
-
Delete a service discovery: To delete a custom service discovery, click Delete in the Operation column. Deleting a custom service discovery stops metric data collection and associated billing.
References
-
After you enable service discovery, you can configure rules to drop unwanted metric data. For more information, see Configure metric dropping.
-
Enabling service discovery starts metric collection, which may incur charges. For more information, see Why am I charged extra after I use Alibaba Cloud Managed Service for Prometheus?.
-
For more information about creating a service discovery job with a ServiceMonitor, see Create a service discovery by using a ServiceMonitor.