Collect custom metrics with a ServiceMonitor

更新时间:
复制 MD 格式

Configure a ServiceMonitor to scrape monitoring metrics from Pods associated with a specific Service in a container cluster. This automates and simplifies Prometheus monitoring.

Limitations

Only container clusters are supported.

Billing

  • Using a ServiceMonitor incurs charges. For more information, see Prometheus instance billing.

  • If you have deployed an open-source Prometheus service with Service Monitor configurations in your cluster, after you connect the cluster to Managed Service for Prometheus, Managed Service for Prometheus will directly inherit the configurations of the original open-source version and incur charges related to Service Monitor.For billing information, see Billing of Prometheus Instances.

Prerequisites

  • You have created a container cluster. For more information, see Create an ACK managed cluster.

  • You have created a Service for Pods that expose monitoring metrics on the ports defined in the Service. For more information, see Service management.

Procedure

  1. Log on to the Cloud Monitor console.

  2. In the navigation pane on the left, click Integration Management.

  3. On the Integrated Environments tab, in the Container Service list, click Metric Scraping in the Actions column of the target container environment to open the Metric Scraping page.

  4. On the Metric Scraping page, click the ServiceMonitor tab.

Enable the feature

On the ServiceMonitor page, click Enable Feature. Once enabled, you can view all ServiceMonitors and their configurations within the current container cluster. ARMS will then scrape monitoring metrics based on the specified scrape interval and path.

Note

This feature is enabled by default.

In the Actions column of the target ServiceMonitor, click Enable.

Manage ServiceMonitors

Add ServiceMonitor

On the ServiceMonitor page, click Create. In the Add ServiceMonitor Configuration panel, configure the required information, and then click Create .

Quick edit

Select the Namespace, Service, and Port for the container cluster. Then, configure the Metric Path and Collection Interval (in seconds). Click Check. If the configuration is valid, click Create .

YAML

Enter a YAML configuration that conforms to the Prometheus ServiceMonitor specification. Then click Check. If the configuration is valid, click Create .

In the sample YAML configuration, apiVersion is monitoring.coreos.com/v1, and kind is ServiceMonitor. The metadata.annotations section must include arms.prometheus.io/discovery: 'true' to enable service discovery. In the spec.endpoints section, configure scraping parameters such as interval: 15s, port: operator, and path: /metrics. You must also configure the namespaceSelector and selector fields.

Edit ServiceMonitor

In the ServiceMonitor list, find the target ServiceMonitor and click Edit Configuration in the Operation column. In the Edit ServiceMonitor Configuration panel, modify the YAML content.

Delete ServiceMonitor

In the ServiceMonitor list, click Delete in the Operation column of the target ServiceMonitor.

Disable ServiceMonitor

In the ServiceMonitor list, click Disable in the Operation column of the target ServiceMonitor. After it is disabled, the ServiceMonitor configuration no longer takes effect.

Disable feature

On the ServiceMonitor page, click Disable Feature. After this feature is disabled, Prometheus no longer discovers new targets based on ServiceMonitor configurations. However, scraping continues for targets that have already been discovered.