All Products
Search
Document Center

:Manage service discoveries

Last Updated:Mar 27, 2024

On the Service Discovery tab, you can view the built-in service discoveries provided by Managed Service for Prometheus. You can also create a ServiceMonitor or PodMonitor to configure collection rules for Managed Service for Prometheus. This topic describes how to manage the service discoveries of a Kubernetes cluster.

Prerequisites

A Prometheus instance for Container Service is created. For more information, see Create a Prometheus instance to monitor an ACK cluster.

Limits

The Kubernetes cluster must be monitored by a Prometheus instance for Container Service.

Procedure

  1. Log on to the ARMS console.

  2. In the left-side navigation pane, choose Managed Service for Prometheus > Instances.

  3. Click the name of the Prometheus instance.

Manage the default service discoveries

Managed Service for Prometheus provides default built-in service discoveries. The default service discoveries are automatically enabled when you connect the Kubernetes cluster to Managed Service for Prometheus. The metrics of pods in all namespaces of the Kubernetes cluster are collected. If a pod contains the following annotations, the default service discoveries collect the metrics of the pod and incurs fees:

  • prometheus.io/path: /metrics

  • prometheus.io/port: "9104"

  • prometheus.io/scrape: "true"

ry

View the default service discoveries

  1. In the left-side navigation pane, click Service Discovery. Then, click the Configurations tab.

  2. Click the Default Service Discovery tab to 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.

  • Enable a default service discovery: Turn on the switch in the Actions column.

    Important

    The service discovery feature is built into Managed Service for Prometheus. When you create a Prometheus instance, the default service discoveries are automatically enabled. After you enable the service discovery feature, you are charged for the metric collection. For more information, see Why am I charged additional fees when I use Managed Service for Prometheus?. If you do not need to collect metric data, you can disable the feature.

Manage custom ServiceMonitors

You can create ServiceMonitors to collect metrics based on your configurations.

Important

You are charged for using ServiceMonitors to collect metrics. For more information about billing, see Billing overview.

Create a ServiceMonitor

You can create a ServiceMonitor if you want to monitor the business data of applications in a Kubernetes cluster, such as order information.

  1. In the left-side navigation pane, click Service Discovery. Then, click the Configurations tab.

  2. On the Configurations tab, click the ServiceMonitor tab. Then, click Add ServiceMonitor.

  3. In the dialog box that appears, enter the configurations and click OK.

    Sample configurations:

    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: tomcat

    After the configurations are complete, the ServiceMonitor appears on the ServiceMonitor tab. wfg

What to do next

On the ServiceMonitor tab, you can perform the following operations:

  • Modify a ServiceMonitor: Click Edit in the Actions column.

  • Delete a ServiceMonitor: Click Delete in the Actions column.

  • Disable a ServiceMonitor: Turn off the switch in the Actions column. You can also click Disable all to disable all the ServiceMonitors that you created.

  • Enable a ServiceMonitor: Turn on the switch in the Actions column.

    Important

    If you enable a ServiceMonitor, you may be charged for metrics that are collected. For more information, see Why am I charged additional fees when I use Managed Service for Prometheus?. If you do not need to collect metric data, you can disable the ServiceMonitor.

Manage PodMonitors

You can create PodMonitors to collect metrics based on your configurations.

Important

You are charged for using PodMonitors to collect metrics. For more information about billing, see Billing overview.

Create a PodMonitor

  1. In the left-side navigation pane, click Service Discovery. Then, click the Configurations tab.

  2. Click the PodMonitor tab. Then, click Add PodMonitor in the upper-right corner.

  3. In the dialog box that appears, enter the configurations and click OK.

    Sample configurations:

    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: /metrics

    After the configurations are complete, the PodMonitor appears on the PodMonitor tab. zv

What to do next

On the PodMonitor tab, you can perform the following operations:

  • Modify a PodMonitor: Click Edit in the Actions column.

  • Delete a PodMonitor: Click Delete in the Actions column.

  • Disable a PodMonitor: Turn off the switch in the Actions column. You can also click Disable all to disable all the PodMonitors that you created.

  • Enable a PodMonitor: Turn on the switch in the Actions column.

    Important

Manage custom service discoveries

You can create custom service discoveries and collect metrics based on the configurations.

Important

You are charged for using custom service discoveries to collect metrics. For more information about billing, see Billing overview.

Create a custom service discovery

  1. In the left-side navigation pane, click Service Discovery. Then, click the Configurations tab.

  2. Click the Custom Service Discovery tab, and then click Add in the upper-right corner.

  3. In the dialog box that appears, enter the configurations and click Save.

    Sample configurations:

    # 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:3000

    After you complete the configurations, the service discovery is displayed on the Custom Service Discovery tab. dh

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.