Manage aggregation task groups
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.
All aggregation task commands are under the
prometheus recording-rulecommand 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.
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.jsonParameter | Type | Description |
| string | Source Prometheus instance ID. Required. |
| string | Request body, either inline JSON or |
| bool | Print an example request body and exit. |
| bool | Print the JSON schema of the request body and exit. |
Required body fields
Field | Description |
| Name of the aggregation task group. |
| RecordingRule YAML configuration content. |
| Target Prometheus instance ID. |
The
aggTaskGroupConfigfield 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) andrequestId.
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 jsonParameter | Type | Description |
| string | Source Prometheus instance ID. Required. |
| 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.jsonParameter | Type | Description |
| string | Source Prometheus instance ID. Required. |
| string | Aggregation task group ID. Required. |
| string | Request body, either inline JSON or |
| bool | Print an example request body and exit. |
| 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-abc123Parameter | Type | Description |
| string | Source Prometheus instance ID. Required. |
| string | Aggregation task group ID. Required. |
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.
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-abc123Parameter | Type | Description |
| string | Source Prometheus instance ID. Required. |
| 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 textParameter | Type | Description |
| string | Source Prometheus instance ID. Required. |
| string | Filter by status ( |
| string | Filter by target Prometheus instance ID. |
| string | Filter by ID list (JSON array, for example |
| string | Filter by name list (JSON array, for example |
| string | Fuzzy search by name. |
| string | Filter by tag (JSON array, field names in lowercase). |
| int32 | Maximum number of results to return. |
| string | Pagination token. |
Limits
The
listcommand is a single-page request and does not automatically paginate.The
createandupdatecommands do not perform CLI-side schema validation. Field-level constraints are validated by the API.The
--tagparameter must be a JSON array with lowercase field names:[{"key":"k","value":"v"}].The
--filter-idsand--filter-namesparameters must be JSON string arrays:["id1","id2"].Use the dedicated
startandstopsubcommands to control the running state. No--statusparameter is available for this purpose.