All Products
Search
Document Center

Application Real-Time Monitoring Service:Obtain container service component metrics through custom collection tasks

Last Updated:Mar 11, 2026

Managed Service for Prometheus collects a default set of container cluster basic metrics through built-in collection jobs. Some component-level metrics, such as kube-state-metrics data, are not included in these defaults. To collect these metrics, create a custom collection task that targets the specific metrics your workloads require.

This topic uses the _kube-state-metrics job as an example to walk through the process.

Prerequisites

Before you begin, make sure that you have:

Step 1: Copy the reference configuration

Copy the existing collection configuration to use as a template.

  1. Log on to the ARMS console. In the left-side navigation pane, click Integration Management.

  2. On the Access Management page, click the target access environment, and then click the Metric Collection tab.

  3. In the left-side navigation pane, click Custom Collection, and then navigate to cs-default-monitor > _kube-state-metrics. Click View Configuration and copy the full configuration.

    Custom Collection navigation showing cs-default-monitor  / /> _kube-state-metrics > View Configuration

Step 2: Create a custom collection task

  1. On the right side of the page, click Custom Collection, and then click Add.

  2. On the Add Custom Collection Task page, set the following parameters.

    Parameter

    Description

    Example

    Task Name

    Name of the custom task. Do not use uppercase letters.

    ksm_demo

    Collection Configuration

    Paste the configuration you copied in Step 1, then add a metric_relabel_configs block at the same level as relabel_configs to filter for the metrics you need. See the following sample configuration.

    See below

    Sample configuration

    This configuration filters three kube-state-metrics values. Replace the metric names in the regex field with the ones your workloads require.

       scrape_configs:
       - job_name: ksm_job
         honor_timestamps: true
         scrape_interval: 30s
         scrape_timeout: 30s
         metrics_path: /metrics
         scheme: http
         follow_redirects: true
    
         ## Add this block to keep only the metrics you need
         metric_relabel_configs:
         - source_labels:
           - __name__
           regex: (kube_cronjob_next_schedule_time|kube_job_status_start_time|kube_job_spec_completions)
           action: keep
         ## Replace the metric names above with the ones required by your workloads
    
         relabel_configs:
         - action: labelmap
           regex: .*label_o11y_aliyun_dev_(.*)
           replacement: $1
         - source_labels:
           - __meta_kubernetes_service_label_app
           - __meta_kubernetes_service_label_k8s_app
           separator: ;
           regex: (kube-state-metrics);.*|.*;(kube-state-metrics)
           replacement: $1
           action: keep
         - source_labels:
           - __meta_kubernetes_pod_container_port_number
           separator: ;
           regex: 8080
           replacement: $1
           action: keep
         - source_labels:
           - __address__
           - __meta_kubernetes_pod_container_port_number
           separator: ;
           regex: ([^:]+)(?::\d+)?;(\d+)
           target_label: __address__
           replacement: $1:$2
           action: replace
         kubernetes_sd_configs:
         - api_server: https://kubernetes.default:8443
           role: endpoints
           authorization:
             type: Bearer
             credentials_file: /var/run/secrets/kubernetes.io/serviceaccount/token
           tls_config:
             insecure_skip_verify: true
           follow_redirects: true
           namespaces:
             names:
             - cs-ask-c8034dddd2cf646318b63faf1********

    The key addition is the metric_relabel_configs block. It uses a keep action with a regex that matches only the specified metric names in source_labels: [__name__]. All other metrics scraped by this job are dropped.

  3. Click Check And Create.

Step 3: Verify the collection task

  1. Click the Self-monitoring tab and confirm that the State of your new task shows UP.

    Self-monitoring tab showing metric status with State UP

  2. Click the Metric Explorer tab and query the metrics you configured. Use the job name from your custom task (for example, ksm_job) as the filter value.

    Note

    The filter value corresponds to the job name specified in your custom collection task.

    Metric Explorer tab for querying metrics