All Products
Search
Document Center

Managed Service for Prometheus:Manage a custom job for an environment instance

Last Updated:Jun 17, 2026

Use Terraform to create and deploy Prometheus scrape jobs to Container Service for Kubernetes (ACK) or Elastic Compute Service (ECS) environment instances. You can configure scrape targets, paths, and intervals to automate metric collection.

Prerequisites

A Container Service for Kubernetes (ACK) environment is created. For more information, see Use Terraform to manage an environment instance.

Limitations

Only Container Service for Kubernetes (ACK) and Elastic Compute Service (ECS) environment instances are supported.

Add a custom job for an environment instance

  1. Create a file named main.tf in a working directory to define the custom job resource.

    provider "alicloud" {
    # access_key = "************"
    # secret_key = "************"
    # region = "cn-beijing"
    }
    # Configure the custom job for the environment instance.
    resource "alicloud_arms_env_custom_job" "my-custom-job1" {
    	env_custom_job_name = "my-custom-job1"
      environment_id = "env-xxxxx" # Replace with the ID of your ACK or ECS environment instance.
      config_yaml    = <<-EOT
          scrape_configs:
          - job_name: job-demo1
            honor_timestamps: false
            honor_labels: false
            scrape_interval: 30s
            scheme: http
            metrics_path: /metric
            static_configs:
            - targets:
              - 127.0.0.1:9090
          - job_name: job-demo2
            honor_timestamps: false
            honor_labels: false
            scrape_interval: 30s
            scheme: http
            metrics_path: /metric
            static_configs:
            - targets:
              - 127.0.0.1:9090
            http_sd_configs:
            - url: 127.0.0.1:9090
              refresh_interval: 30s
    	EOT
    }
  2. Run the following command to initialize the Terraform working directory.

    terraform init

    Expected output:

    Initializing the backend...
    
    Initializing provider plugins...
    - Checking for available provider plugins...
    - Downloading plugin for provider "alicloud" (hashicorp/alicloud) 1.90.1...
    ...
    
    You may now begin working with Terraform. Try running "terraform plan" to see
    any changes that are required for your infrastructure. All Terraform commands
    should now work.
    
    If you ever set or change modules or backend configuration for Terraform,
    rerun this command to reinitialize your working directory. If you forget, other
    commands will detect it and remind you to do so if necessary.
  3. Run the following command to generate an execution plan.

    terraform plan

    Expected output:

    Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
     + create
    
    Terraform will perform the following actions:
    
     # alicloud_arms_env_custom_job.myCustomJob1 will be created
     + resource "alicloud_arms_env_custom_job" "myCustomJob1" {
    				env_custom_job_name = "myCustomJob1"
    				environment_id = "xxx"
    				config_yaml = ....
     }
    
    Plan: 1 to add, 0 to change, 0 to destroy.
  4. Run the following command to create the custom job.

    terraform apply

    Expected output:

    Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
     + create
    
    Terraform will perform the following actions:
    
     # alicloud_arms_env_custom_job.myCustomJob1 will be created
     + resource "alicloud_arms_env_custom_job" "myCustomJob1" {
    				env_custom_job_name = "myCustomJob1"
    				environment_id = "xxx"
    				config_yaml = ....
     }
    
    Plan: 1 to add, 0 to change, 0 to destroy.
    
    Do you want to perform these actions?
     Terraform will perform the actions described above.
     Only 'yes' will be accepted to approve.
    
     Enter a value: yes

    At the Enter a value prompt, type yes and press Enter to create the custom job.

  5. Log on to the Cloud Monitor console.

  6. In the navigation pane on the left, click Integration Management. On the Integration Management page, find your target environment instance and click its name.

  7. On the environment details page, click the Metric Scraping tab, and then click Customize Collection. Verify that the custom job is listed.

Delete the custom job

  1. Run the following command to delete the custom job.

    terraform destroy

    Expected output:

    ...
    Do you really want to destroy all resources?
     Terraform will destroy all your managed infrastructure, as shown above.
     There is no undo. Only 'yes' will be accepted to confirm.
    
     Enter a value: yes
    ...
    Destroy complete! Resources: 1 destroyed.

    At the Enter a value prompt, type yes and press Enter.

  2. Log on to the Cloud Monitor console.

  3. In the navigation pane on the left, click Integration Management. On the Integration Management page, find your target environment instance and click its name.

  4. On the environment details page, click the Metric Scraping tab, and then click Customize Collection. Verify that the custom job is no longer listed.