Manage aggregation task groups

Updated at:

The aliyun cms2 prometheus recording-rule command group is used to manage Prometheus aggregation task groups (AggTaskGroup) for RecordingRule pre-aggregation. An aggregation task reads metric data from a source Prometheus instance, executes the RecordingRule calculation, and writes the results to a destination instance. This process reduces the computational load for queries.

Note
  • All aggregation task commands are under the prometheus recording-rule command group (for example, aliyun cms2 prometheus recording-rule list).

  • The source instance parameter is --prometheus-id, and the aggregation task group ID parameter is --group-id.

Important

Aggregation tasks support only Prometheus V2 instances.

Background information

Some PromQL queries consume significant resources at query time. You can use pre-aggregation rules to shift calculations to the write path, which reduces query-side resource consumption, simplifies PromQL complexity, and improves query performance.

Open-source RecordingRules exist in rule group form, and each rule group can contain multiple rules. In Cloud Monitor aggregation tasks, the aggregation rule configuration format is compatible with open-source RecordingRule. The aggTaskGroupConfig field in the task configuration contains RecordingRule rules in YAML format.

Prerequisites

  • The CLI tool is installed and configured.

  • You have created a Prometheus V2 instance.

  • The AliyunLogETLRole role is required for aggregation task scheduling.

prometheus recording-rule create — Create an aggregation task group

Create an aggregation task group under a source Prometheus instance.

# Create an aggregation task group
aliyun cms2 prometheus recording-rule create --prometheus-id rw-xxx --body '{
  "aggTaskGroupName": "my-recording-rules",
  "aggTaskGroupConfig": "groups:\n- name: node.rules\n  rules:\n  - record: ...\n    expr: ...",
  "targetPrometheusId": "rw-yyy"
}'

# Create from a JSON file
aliyun cms2 prometheus recording-rule create --prometheus-id rw-xxx --body @./recording-rule.json

Parameter

Type

Description

--prometheus-id

string

Source Prometheus instance ID. Required.

--body

string

Request body, either inline JSON or @file.json. Required.

--show-example-body

bool

Print an example request body and exit.

--show-schema

bool

Print the JSON schema of the request body and exit.

Required body fields

Field

Description

aggTaskGroupName

Name of the aggregation task group.

aggTaskGroupConfig

RecordingRule YAML configuration content.

targetPrometheusId

Target Prometheus instance ID.

Note
  • The aggTaskGroupConfig field contains RecordingRule YAML in a format compatible with open-source Prometheus.

  • Other optional fields (scheduleMode, delay, and others) use API default values.

  • The response returns aggTaskGroupId (the generated ID) and requestId.

prometheus recording-rule get — Query an aggregation task group

Retrieve the complete details of an aggregation task group.

aliyun cms2 prometheus recording-rule get --prometheus-id rw-xxx --group-id aggTaskGroup-abc123

# JSON output
aliyun cms2 prometheus recording-rule get --prometheus-id rw-xxx --group-id aggTaskGroup-abc123 -o json

Parameter

Type

Description

--prometheus-id

string

Source Prometheus instance ID. Required.

--group-id

string

Aggregation task group ID. Required.

prometheus recording-rule update — Update an aggregation task group

Update the configuration of an existing aggregation task group. Only fields included in the body are modified.

aliyun cms2 prometheus recording-rule update --prometheus-id rw-xxx --group-id aggTaskGroup-abc123 \
  --body '{"aggTaskGroupConfig": "...", "targetPrometheusId": "rw-yyy"}'

# Update from a file
aliyun cms2 prometheus recording-rule update --prometheus-id rw-xxx --group-id aggTaskGroup-abc123 \
  --body @./updated-config.json

Parameter

Type

Description

--prometheus-id

string

Source Prometheus instance ID. Required.

--group-id

string

Aggregation task group ID. Required.

--body

string

Request body, either inline JSON or @file.json. Required.

--show-example-body

bool

Print an example request body and exit.

--show-schema

bool

Print the JSON schema of the request body and exit.

prometheus recording-rule start/stop — Start /Stop an aggregation task group

Start or stop an aggregation task group. These commands call the UpdateAggTaskGroupStatus API. The start command sets the status to Running, and the stop command sets the status to Stopped.

# Start an aggregation task group
aliyun cms2 prometheus recording-rule start \
  --prometheus-id rw-xxx --group-id aggTaskGroup-abc123

# Stop an aggregation task group
aliyun cms2 prometheus recording-rule stop \
  --prometheus-id rw-xxx --group-id aggTaskGroup-abc123

Parameter

Type

Description

--prometheus-id

string

Source Prometheus instance ID. Required.

--group-id

string

Aggregation task group ID. Required.

Note

Use update to modify the configuration. Use start and stop to control the running state.

prometheus recording-rule delete — Delete an aggregation task group

Delete a specified aggregation task group.

Warning

This operation is irreversible. The aggregation task group and its historical output cannot be recovered.

aliyun cms2 prometheus recording-rule delete --prometheus-id rw-xxx --group-id aggTaskGroup-abc123

Parameter

Type

Description

--prometheus-id

string

Source Prometheus instance ID. Required.

--group-id

string

Aggregation task group ID. Required.

prometheus recording-rule list — List aggregation task groups

List all aggregation task groups under a specified Prometheus instance. This command supports multiple filter conditions and pagination.

# List all task groups
aliyun cms2 prometheus recording-rule list --prometheus-id rw-xxx

# Filter by status
aliyun cms2 prometheus recording-rule list --prometheus-id rw-xxx --status Running

# Search by name
aliyun cms2 prometheus recording-rule list --prometheus-id rw-xxx --query "node"

# Filter by target instance
aliyun cms2 prometheus recording-rule list --prometheus-id rw-xxx --target-prometheus-id rw-yyy

# Filter by tag
aliyun cms2 prometheus recording-rule list --prometheus-id rw-xxx --tag '[{"key":"env","value":"prod"}]'

# Paged query
aliyun cms2 prometheus recording-rule list --prometheus-id rw-xxx --max-results 10
aliyun cms2 prometheus recording-rule list --prometheus-id rw-xxx --max-results 10 --next-token "xxx"

# Text (CSV) output
aliyun cms2 prometheus recording-rule list --prometheus-id rw-xxx -o text

Parameter

Type

Description

--prometheus-id

string

Source Prometheus instance ID. Required.

--status

string

Filter by status (Running or Stopped).

--target-prometheus-id

string

Filter by target Prometheus instance ID.

--filter-ids

string

Filter by ID list (JSON array, for example '["aggTaskGroup-xxx"]').

--filter-names

string

Filter by name list (JSON array, for example '["name1"]').

--query

string

Fuzzy search by name.

--tag

string

Filter by tag (JSON array, field names in lowercase).

--max-results

int32

Maximum number of results to return.

--next-token

string

Pagination token.

Limits

  • The list command is a single-page request and does not automatically paginate.

  • The create and update commands do not perform CLI-side schema validation. Field-level constraints are validated by the API.

  • The --tag parameter must be a JSON array with lowercase field names: [{"key":"k","value":"v"}].

  • The --filter-ids and --filter-names parameters must be JSON string arrays: ["id1","id2"].

  • Use the dedicated start and stop subcommands to control the running state. No --status parameter is available for this purpose.