Todos os produtos
Search
Central de documentação

Resource Orchestration Service:ALIYUN::CMS2::AggTaskGroup

Última atualização: Oct 11, 2026

O tipo ALIYUN::CMS2::AggTaskGroup cria grupos de tarefas de agregação.

Sintaxe

{
  "Type": "ALIYUN::CMS2::AggTaskGroup",
  "Properties": {
    "AggTaskGroupName": String,
    "AggTaskGroupConfig": String,
    "InstanceId": String,
    "TargetPrometheusId": String,
    "AggTaskGroupConfigType": String,
    "CronExpr": String,
    "Description": String,
    "Delay": Integer,
    "FromTime": Integer,
    "MaxRetries": Integer,
    "MaxRunTimeInSeconds": Integer,
    "OverrideIfExists": Boolean,
    "PrecheckString": Map,
    "Status": String,
    "ScheduleTimeExpr": String,
    "ScheduleMode": String,
    "ToTime": Integer,
    "Tags": List
  }
}

Propriedades

Propriedade

Tipo

Obrigatório

Editável

Descrição

Restrições

AggTaskGroupConfig

String

Sim

Sim

Configuração do grupo de tarefas de agregação.

Somente o formato RecordingRuleYaml é compatível. A configuração deve atender aos requisitos de formato do RecordingRule do Prometheus open source. Exemplo:

groups:
      - name: node.rules
        interval: 60s
        rules:
          - record: node_namespace_pod:kube_pod_info:
            expr: "max(label_replace(kube_pod_info{job=\"kubernetes-pods-kube-state-metrics\"}, \"pod\", \"$1\", \"pod\", \"(.*)\")) by (node, namespace, pod, cluster)"

AggTaskGroupName

String

Sim

Sim

Nome do grupo de tarefas de agregação.

Nenhuma

InstanceId

String

Sim

Não

ID da instância Prometheus de origem da qual o grupo de tarefas de agregação lê dados.

Nenhuma

TargetPrometheusId

String

Sim

Sim

ID da instância Prometheus de destino do grupo de tarefas de agregação.

Nenhuma

AggTaskGroupConfigType

String

Não

Sim

Tipo de configuração do grupo de tarefas de agregação.

Padrão:

  • RecordingRuleYaml

CronExpr

String

Não

Sim

Expressão cron.

Por exemplo, 0/1 indica que a tarefa é agendada a cada minuto, começando no minuto 0.

Delay

Integer

Não

Sim

Atraso fixo para agendamento.

Unidade: segundos.

Valor padrão: 30.

Description

String

Não

Sim

Descrição do grupo de tarefas de agregação.

Nenhuma

FromTime

Integer

Não

Sim

Timestamp em segundos correspondente ao horário de início do agendamento.

Nenhuma

MaxRetries

Integer

Não

Sim

Número máximo de novas tentativas para uma tarefa de agregação.

Valor padrão: 20.

MaxRunTimeInSeconds

Integer

Não

Sim

Tempo máximo de execução de uma tarefa de agregação.

Unidade: segundos.

Valor padrão: 600.

OverrideIfExists

Boolean

Não

Não

Define se um grupo de tarefas de agregação existente com o mesmo nome será sobrescrito e atualizado durante a criação.

Nenhuma

PrecheckString

Map

Não

Sim

Configuração de pré-verificação.

Nenhuma configuração especificada por padrão. A string de entrada deve ser analisada corretamente como JSON. Exemplo:

{
  "policy": "skip",
  "prometheusId": "xxx",
  "query": "scalar(sum(count_over_time(up{job=\"_arms/kubelet/cadvisor\"}[15s])) / 21)",
  "threshold": 0.5,
  "timeout": 15,
  "type": "promql"
}

ScheduleMode

String

Não

Sim

Modo de agendamento.

Valores válidos:

  • Cron

  • FixedRate

ScheduleTimeExpr

String

Não

Sim

Expressão de tempo de agendamento.

(Recomendado) Use @s ou @m para especificar a granularidade de arredondamento da janela de tempo de agendamento. Valor padrão: @m.

Status

String

Não

Sim

Status do grupo de tarefas de agregação.

Valores válidos:

  • Running

  • Stopped

Tags

List

Não

Sim

Tags do grupo de tarefas de agregação.

Para mais informações, consulte Tags properties.

ToTime

Integer

Não

Sim

Timestamp em segundos correspondente ao horário de término do agendamento.

O valor 0 indica que o agendamento nunca para.

Sintaxe de Tags

"Tags": [
  {
    "Value": String,
    "Key": String
  }
]

Propriedades de Tags

Propriedade

Tipo

Obrigatório

Editável

Descrição

Restrições

Key

String

Sim

Não

Chave da tag.

Nenhuma

Value

String

Não

Não

Valor da tag.

Nenhuma

Valores de retorno

Fn::GetAtt

  • AggTaskGroupName: nome do grupo de tarefas de agregação.

  • Status: status atual do grupo de tarefas de agregação.

  • AggTaskGroupConfigHash: hash de configuração do grupo de tarefas de agregação.

  • AggTaskGroupId: ID do grupo de tarefas de agregação.

  • SourcePrometheusId: ID da instância Prometheus de origem do grupo de tarefas de agregação.

Exemplos

Cenário 1: Criar um grupo de tarefas de agregação para uma instância Prometheus existente

ROSTemplateFormatVersion: '2015-09-01'
Description:
  zh-cn: Create a simple aggregation task group for an existing Prometheus instance by using the default scheduling configuration and basic recording rules.
  en: Create a simple aggregation task group for an existing Prometheus instance with default schedule configuration and basic recording rules.
Parameters:
  SourcePrometheusId:
    Type: String
    Label:
      zh-cn: Source Prometheus Instance ID
      en: Source Prometheus Instance ID
    Description:
      zh-cn: The ID of the source Prometheus instance from which the aggregation task group reads data.
      en: The ID of the source Prometheus instance that the agg task group reads data from.
  TargetPrometheusId:
    Type: String
    Label:
      zh-cn: Target Prometheus Instance ID
      en: Target Prometheus Instance ID
    Description:
      zh-cn: The ID of the target Prometheus instance to which the aggregation results are written.
      en: The ID of the target Prometheus instance that the agg task group writes data to.
  AggTaskGroupName:
    Type: String
    Label:
      zh-cn: Aggregation Task Group Name
      en: Agg Task Group Name
    Description:
      zh-cn: The name of the aggregation task group.
      en: The name of the aggregation task group.
    Default: simple-agg-task-group
Resources:
  AggTaskGroup:
    Type: ALIYUN::CMS2::AggTaskGroup
    Properties:
      AggTaskGroupName:
        Ref: AggTaskGroupName
      InstanceId:
        Ref: SourcePrometheusId
      TargetPrometheusId:
        Ref: TargetPrometheusId
      AggTaskGroupConfig: |-
        groups:
          - name: basic_rules
            rules:
              - record: job:node_cpu_usage:avg_rate5m
                expr: avg by (job) (rate(node_cpu_seconds_total{mode!="idle"}[5m]))
      Description: Simple aggregation task group
Outputs:
  AggTaskGroupId:
    Description:
      zh-cn: Aggregation task group ID.
      en: Agg task group ID.
    Label:
      zh-cn: Aggregation Task Group ID
      en: Agg Task Group ID
    Value:
      Fn::GetAtt:
        - AggTaskGroup
        - AggTaskGroupId
  AggTaskGroupName:
    Description:
      zh-cn: Aggregation task group name.
      en: Agg task group name.
    Label:
      zh-cn: Aggregation Task Group Name
      en: Agg Task Group Name
    Value:
      Fn::GetAtt:
        - AggTaskGroup
        - AggTaskGroupName
  Status:
    Description:
      zh-cn: Aggregation task group status.
      en: Agg task group status.
    Label:
      zh-cn: Aggregation Task Group Status
      en: Status
    Value:
      Fn::GetAtt:
        - AggTaskGroup
        - Status
Metadata:
  ALIYUN::ROS::Interface:
    ParameterGroups:
      - Parameters:
          - SourcePrometheusId
          - TargetPrometheusId
          - AggTaskGroupName
{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Description": {
    "zh-cn": "Create a simple aggregation task group for an existing Prometheus instance by using the default scheduling configuration and basic recording rules.",
    "en": "Create a simple aggregation task group for an existing Prometheus instance with default schedule configuration and basic recording rules."
  },
  "Parameters": {
    "SourcePrometheusId": {
      "Type": "String",
      "Label": {
        "zh-cn": "Source Prometheus Instance ID",
        "en": "Source Prometheus Instance ID"
      },
      "Description": {
        "zh-cn": "The ID of the source Prometheus instance from which the aggregation task group reads data.",
        "en": "The ID of the source Prometheus instance that the agg task group reads data from."
      }
    },
    "TargetPrometheusId": {
      "Type": "String",
      "Label": {
        "zh-cn": "Target Prometheus Instance ID",
        "en": "Target Prometheus Instance ID"
      },
      "Description": {
        "zh-cn": "The ID of the target Prometheus instance to which the aggregation results are written.",
        "en": "The ID of the target Prometheus instance that the agg task group writes data to."
      }
    },
    "AggTaskGroupName": {
      "Type": "String",
      "Label": {
        "zh-cn": "Aggregation Task Group Name",
        "en": "Agg Task Group Name"
      },
      "Description": {
        "zh-cn": "The name of the aggregation task group.",
        "en": "The name of the aggregation task group."
      },
      "Default": "simple-agg-task-group"
    }
  },
  "Resources": {
    "AggTaskGroup": {
      "Type": "ALIYUN::CMS2::AggTaskGroup",
      "Properties": {
        "AggTaskGroupName": {
          "Ref": "AggTaskGroupName"
        },
        "InstanceId": {
          "Ref": "SourcePrometheusId"
        },
        "TargetPrometheusId": {
          "Ref": "TargetPrometheusId"
        },
        "AggTaskGroupConfig": "groups:\n  - name: basic_rules\n    rules:\n      - record: job:node_cpu_usage:avg_rate5m\n        expr: avg by (job) (rate(node_cpu_seconds_total{mode!=\"idle\"}[5m]))",
        "Description": "Simple aggregation task group"
      }
    }
  },
  "Outputs": {
    "AggTaskGroupId": {
      "Description": {
        "zh-cn": "Aggregation task group ID.",
        "en": "Agg task group ID."
      },
      "Label": {
        "zh-cn": "Aggregation Task Group ID",
        "en": "Agg Task Group ID"
      },
      "Value": {
        "Fn::GetAtt": [
          "AggTaskGroup",
          "AggTaskGroupId"
        ]
      }
    },
    "AggTaskGroupName": {
      "Description": {
        "zh-cn": "Aggregation task group name.",
        "en": "Agg task group name."
      },
      "Label": {
        "zh-cn": "Aggregation Task Group Name",
        "en": "Agg Task Group Name"
      },
      "Value": {
        "Fn::GetAtt": [
          "AggTaskGroup",
          "AggTaskGroupName"
        ]
      }
    },
    "Status": {
      "Description": {
        "zh-cn": "Aggregation task group status.",
        "en": "Agg task group status."
      },
      "Label": {
        "zh-cn": "Aggregation Task Group Status",
        "en": "Status"
      },
      "Value": {
        "Fn::GetAtt": [
          "AggTaskGroup",
          "Status"
        ]
      }
    }
  },
  "Metadata": {
    "ALIYUN::ROS::Interface": {
      "ParameterGroups": [
        {
          "Parameters": [
            "SourcePrometheusId",
            "TargetPrometheusId",
            "AggTaskGroupName"
          ]
        }
      ]
    }
  }
}

Cenário 2: Criar instâncias Prometheus e configurar um grupo de tarefas de agregação com agendamento Cron

ROSTemplateFormatVersion: '2015-09-01'
Description:
  zh-cn: Create source and target Prometheus instances and configure an aggregation task group that uses Cron scheduling, a custom retry policy, and multiple recording rules.
  en: Create source and target Prometheus instances, configure aggregation task group with Cron schedule mode, custom retry policy, and multiple recording rules.
Parameters:
  PrometheusInstanceNamePrefix:
    Type: String
    Label:
      zh-cn: Prometheus Instance Name Prefix
      en: Prometheus Instance Name Prefix
    Description:
      zh-cn: The name prefix of the source and target Prometheus instances.
      en: Name prefix for source and target Prometheus instances.
    Default: monitoring
    MinLength: 1
    MaxLength: 100
  StorageDuration:
    Type: Number
    Label:
      zh-cn: Storage Duration (Days)
      en: Storage Duration (Days)
    Description:
      zh-cn: The data retention period of the Prometheus instance.
      en: Data storage duration of the Prometheus instance.
    AllowedValues:
      - 15
      - 30
      - 60
      - 90
      - 180
    Default: 90
  AggTaskGroupName:
    Type: String
    Label:
      zh-cn: Aggregation Task Group Name
      en: Agg Task Group Name
    Description:
      zh-cn: The name of the aggregation task group.
      en: The name of the aggregation task group.
    Default: cron-agg-task-group
  CronExpr:
    Type: String
    Label:
      zh-cn: Cron Expression
      en: Cron Expression
    Description:
      zh-cn: Cron scheduling expression. For example, "0/5 * * * *" runs every 5 minutes.
      en: Cron schedule expression, e.g. "0/5 * * * *" means every 5 minutes.
    Default: 0/5 * * * *
  MaxRetries:
    Type: Number
    Label:
      zh-cn: Maximum Number of Retries
      en: Max Retries
    Description:
      zh-cn: The maximum number of retries for the aggregation task.
      en: The maximum number of retries for executing the agg task.
    Default: 20
  MaxRunTimeInSeconds:
    Type: Number
    Label:
      zh-cn: Maximum Runtime (Seconds)
      en: Max Run Time (Seconds)
    Description:
      zh-cn: The maximum runtime of the aggregation task.
      en: The maximum run time for executing the agg task in seconds.
    Default: 600
Resources:
  SourcePrometheus:
    Type: ALIYUN::CMS2::PrometheusInstance
    Properties:
      PrometheusInstanceName:
        Fn::Sub: ${PrometheusInstanceNamePrefix}-source
      StorageDuration:
        Ref: StorageDuration
      ArchiveDuration: 0
      PaymentType: POSTPAY
      EnableAuthFreeRead: true
      EnableAuthFreeWrite: false
      EnableAuthToken: true
  TargetPrometheus:
    Type: ALIYUN::CMS2::PrometheusInstance
    Properties:
      PrometheusInstanceName:
        Fn::Sub: ${PrometheusInstanceNamePrefix}-target
      StorageDuration:
        Ref: StorageDuration
      ArchiveDuration: 0
      PaymentType: POSTPAY
      EnableAuthFreeRead: true
      EnableAuthFreeWrite: false
      EnableAuthToken: true
  AggTaskGroup:
    Type: ALIYUN::CMS2::AggTaskGroup
    DependsOn:
      - SourcePrometheus
      - TargetPrometheus
    Properties:
      AggTaskGroupName:
        Ref: AggTaskGroupName
      InstanceId:
        Fn::GetAtt:
          - SourcePrometheus
          - PrometheusInstanceId
      TargetPrometheusId:
        Fn::GetAtt:
          - TargetPrometheus
          - PrometheusInstanceId
      ScheduleMode: Cron
      CronExpr:
        Ref: CronExpr
      MaxRetries:
        Ref: MaxRetries
      MaxRunTimeInSeconds:
        Ref: MaxRunTimeInSeconds
      Delay: 60
      ScheduleTimeExpr: '@m'
      OverrideIfExists: true
      Description: Aggregation task group with Cron schedule and custom retry policy
      AggTaskGroupConfig: |-
        groups:
          - name: cpu_aggregation
            rules:
              - record: job:node_cpu_usage:avg_rate5m
                expr: avg by (job) (rate(node_cpu_seconds_total{mode!="idle"}[5m]))
              - record: job:node_cpu_usage:max_rate5m
                expr: max by (job) (rate(node_cpu_seconds_total{mode!="idle"}[5m]))
          - name: memory_aggregation
            rules:
              - record: job:node_memory_usage:avg
                expr: avg by (job) (node_memory_MemTotal_bytes - node_memory_MemAvailable_bytes)
              - record: job:node_memory_usage:percent
                expr: avg by (job) ((node_memory_MemTotal_bytes - node_memory_MemAvailable_bytes) / node_memory_MemTotal_bytes * 100)
      Tags:
        - Key: Environment
          Value: Production
        - Key: Team
          Value: SRE
Outputs:
  AggTaskGroupId:
    Description:
      zh-cn: Aggregation task group ID.
      en: Agg task group ID.
    Label:
      zh-cn: Aggregation Task Group ID
      en: Agg Task Group ID
    Value:
      Fn::GetAtt:
        - AggTaskGroup
        - AggTaskGroupId
  SourcePrometheusId:
    Description:
      zh-cn: Source Prometheus instance ID.
      en: Source Prometheus instance ID.
    Label:
      zh-cn: Source Prometheus Instance ID
      en: Source Prometheus ID
    Value:
      Fn::GetAtt:
        - SourcePrometheus
        - PrometheusInstanceId
  TargetPrometheusId:
    Description:
      zh-cn: Target Prometheus instance ID.
      en: Target Prometheus instance ID.
    Label:
      zh-cn: Target Prometheus Instance ID
      en: Target Prometheus ID
    Value:
      Fn::GetAtt:
        - TargetPrometheus
        - PrometheusInstanceId
  AggTaskGroupStatus:
    Description:
      zh-cn: Aggregation task group status.
      en: Agg task group status.
    Label:
      zh-cn: Aggregation Task Group Status
      en: Status
    Value:
      Fn::GetAtt:
        - AggTaskGroup
        - Status
Metadata:
  ALIYUN::ROS::Interface:
    ParameterGroups:
      - Parameters:
          - PrometheusInstanceNamePrefix
          - StorageDuration
      - Parameters:
          - AggTaskGroupName
          - CronExpr
          - MaxRetries
          - MaxRunTimeInSeconds
{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Description": {
    "zh-cn": "Create source and target Prometheus instances and configure an aggregation task group that uses Cron scheduling, a custom retry policy, and multiple recording rules.",
    "en": "Create source and target Prometheus instances, configure aggregation task group with Cron schedule mode, custom retry policy, and multiple recording rules."
  },
  "Parameters": {
    "PrometheusInstanceNamePrefix": {
      "Type": "String",
      "Label": {
        "zh-cn": "Prometheus Instance Name Prefix",
        "en": "Prometheus Instance Name Prefix"
      },
      "Description": {
        "zh-cn": "The name prefix of the source and target Prometheus instances.",
        "en": "Name prefix for source and target Prometheus instances."
      },
      "Default": "monitoring",
      "MinLength": 1,
      "MaxLength": 100
    },
    "StorageDuration": {
      "Type": "Number",
      "Label": {
        "zh-cn": "Storage Duration (Days)",
        "en": "Storage Duration (Days)"
      },
      "Description": {
        "zh-cn": "The data retention period of the Prometheus instance.",
        "en": "Data storage duration of the Prometheus instance."
      },
      "AllowedValues": [
        15,
        30,
        60,
        90,
        180
      ],
      "Default": 90
    },
    "AggTaskGroupName": {
      "Type": "String",
      "Label": {
        "zh-cn": "Aggregation Task Group Name",
        "en": "Agg Task Group Name"
      },
      "Description": {
        "zh-cn": "The name of the aggregation task group.",
        "en": "The name of the aggregation task group."
      },
      "Default": "cron-agg-task-group"
    },
    "CronExpr": {
      "Type": "String",
      "Label": {
        "zh-cn": "Cron Expression",
        "en": "Cron Expression"
      },
      "Description": {
        "zh-cn": "Cron scheduling expression. For example, \"0/5 * * * *\" runs every 5 minutes.",
        "en": "Cron schedule expression, e.g. \"0/5 * * * *\" means every 5 minutes."
      },
      "Default": "0/5 * * * *"
    },
    "MaxRetries": {
      "Type": "Number",
      "Label": {
        "zh-cn": "Maximum Number of Retries",
        "en": "Max Retries"
      },
      "Description": {
        "zh-cn": "The maximum number of retries for the aggregation task.",
        "en": "The maximum number of retries for executing the agg task."
      },
      "Default": 20
    },
    "MaxRunTimeInSeconds": {
      "Type": "Number",
      "Label": {
        "zh-cn": "Maximum Runtime (Seconds)",
        "en": "Max Run Time (Seconds)"
      },
      "Description": {
        "zh-cn": "The maximum runtime of the aggregation task.",
        "en": "The maximum run time for executing the agg task in seconds."
      },
      "Default": 600
    }
  },
  "Resources": {
    "SourcePrometheus": {
      "Type": "ALIYUN::CMS2::PrometheusInstance",
      "Properties": {
        "PrometheusInstanceName": {
          "Fn::Sub": "${PrometheusInstanceNamePrefix}-source"
        },
        "StorageDuration": {
          "Ref": "StorageDuration"
        },
        "ArchiveDuration": 0,
        "PaymentType": "POSTPAY",
        "EnableAuthFreeRead": true,
        "EnableAuthFreeWrite": false,
        "EnableAuthToken": true
      }
    },
    "TargetPrometheus": {
      "Type": "ALIYUN::CMS2::PrometheusInstance",
      "Properties": {
        "PrometheusInstanceName": {
          "Fn::Sub": "${PrometheusInstanceNamePrefix}-target"
        },
        "StorageDuration": {
          "Ref": "StorageDuration"
        },
        "ArchiveDuration": 0,
        "PaymentType": "POSTPAY",
        "EnableAuthFreeRead": true,
        "EnableAuthFreeWrite": false,
        "EnableAuthToken": true
      }
    },
    "AggTaskGroup": {
      "Type": "ALIYUN::CMS2::AggTaskGroup",
      "DependsOn": [
        "SourcePrometheus",
        "TargetPrometheus"
      ],
      "Properties": {
        "AggTaskGroupName": {
          "Ref": "AggTaskGroupName"
        },
        "InstanceId": {
          "Fn::GetAtt": [
            "SourcePrometheus",
            "PrometheusInstanceId"
          ]
        },
        "TargetPrometheusId": {
          "Fn::GetAtt": [
            "TargetPrometheus",
            "PrometheusInstanceId"
          ]
        },
        "ScheduleMode": "Cron",
        "CronExpr": {
          "Ref": "CronExpr"
        },
        "MaxRetries": {
          "Ref": "MaxRetries"
        },
        "MaxRunTimeInSeconds": {
          "Ref": "MaxRunTimeInSeconds"
        },
        "Delay": 60,
        "ScheduleTimeExpr": "@m",
        "OverrideIfExists": true,
        "Description": "Aggregation task group with Cron schedule and custom retry policy",
        "AggTaskGroupConfig": "groups:\n  - name: cpu_aggregation\n    rules:\n      - record: job:node_cpu_usage:avg_rate5m\n        expr: avg by (job) (rate(node_cpu_seconds_total{mode!=\"idle\"}[5m]))\n      - record: job:node_cpu_usage:max_rate5m\n        expr: max by (job) (rate(node_cpu_seconds_total{mode!=\"idle\"}[5m]))\n  - name: memory_aggregation\n    rules:\n      - record: job:node_memory_usage:avg\n        expr: avg by (job) (node_memory_MemTotal_bytes - node_memory_MemAvailable_bytes)\n      - record: job:node_memory_usage:percent\n        expr: avg by (job) ((node_memory_MemTotal_bytes - node_memory_MemAvailable_bytes) / node_memory_MemTotal_bytes * 100)",
        "Tags": [
          {
            "Key": "Environment",
            "Value": "Production"
          },
          {
            "Key": "Team",
            "Value": "SRE"
          }
        ]
      }
    }
  },
  "Outputs": {
    "AggTaskGroupId": {
      "Description": {
        "zh-cn": "Aggregation task group ID.",
        "en": "Agg task group ID."
      },
      "Label": {
        "zh-cn": "Aggregation Task Group ID",
        "en": "Agg Task Group ID"
      },
      "Value": {
        "Fn::GetAtt": [
          "AggTaskGroup",
          "AggTaskGroupId"
        ]
      }
    },
    "SourcePrometheusId": {
      "Description": {
        "zh-cn": "Source Prometheus instance ID.",
        "en": "Source Prometheus instance ID."
      },
      "Label": {
        "zh-cn": "Source Prometheus Instance ID",
        "en": "Source Prometheus ID"
      },
      "Value": {
        "Fn::GetAtt": [
          "SourcePrometheus",
          "PrometheusInstanceId"
        ]
      }
    },
    "TargetPrometheusId": {
      "Description": {
        "zh-cn": "Target Prometheus instance ID.",
        "en": "Target Prometheus instance ID."
      },
      "Label": {
        "zh-cn": "Target Prometheus Instance ID",
        "en": "Target Prometheus ID"
      },
      "Value": {
        "Fn::GetAtt": [
          "TargetPrometheus",
          "PrometheusInstanceId"
        ]
      }
    },
    "AggTaskGroupStatus": {
      "Description": {
        "zh-cn": "Aggregation task group status.",
        "en": "Agg task group status."
      },
      "Label": {
        "zh-cn": "Aggregation Task Group Status",
        "en": "Status"
      },
      "Value": {
        "Fn::GetAtt": [
          "AggTaskGroup",
          "Status"
        ]
      }
    }
  },
  "Metadata": {
    "ALIYUN::ROS::Interface": {
      "ParameterGroups": [
        {
          "Parameters": [
            "PrometheusInstanceNamePrefix",
            "StorageDuration"
          ]
        },
        {
          "Parameters": [
            "AggTaskGroupName",
            "CronExpr",
            "MaxRetries",
            "MaxRunTimeInSeconds"
          ]
        }
      ]
    }
  }
}

Cenário 3: Criar uma solução completa de agregação de dados de monitoramento

ROSTemplateFormatVersion: '2015-09-01'
Description:
  zh-cn: Create a complete monitoring data aggregation solution including an SLS log project, a CMS2 workspace, multiple Prometheus instance groups, and multiple aggregation task groups with recording rules of different granularities, enabling multidimensional monitoring data aggregation and centralized management.
  en: Create a complete monitoring data aggregation solution including SLS log project, CMS2 workspace, multiple Prometheus instance groups, and multiple aggregation task groups with different granularity recording rules for multi-dimensional monitoring data aggregation and centralized management.
Parameters:
  CommonName:
    Type: String
    Label:
      zh-cn: Resource Name Prefix
      en: Resource Name Prefix
    Description:
      zh-cn: The common prefix for all resource names.
      en: Unified name prefix for all resources.
    Default: monitor-center
    MinLength: 1
    MaxLength: 50
  StorageDuration:
    Type: Number
    Label:
      zh-cn: Storage Duration (Days)
      en: Storage Duration (Days)
    Description:
      zh-cn: The data retention period of the Prometheus instance.
      en: Data storage duration of the Prometheus instance.
    AllowedValues:
      - 15
      - 30
      - 60
      - 90
      - 180
    Default: 90
  SourcePrometheusCount:
    Type: Number
    Label:
      zh-cn: Number of Source Prometheus Instances
      en: Source Prometheus Instance Count
    Description:
      zh-cn: The number of source Prometheus instances to create.
      en: Number of source Prometheus instances to create.
    AllowedValues:
      - 1
      - 2
    Default: 2
Resources:
  SlsProject:
    Type: ALIYUN::SLS::Project
    Properties:
      Name:
        Fn::Sub: ${CommonName}-sls
      Description: SLS project for monitoring workspace
  Workspace:
    Type: ALIYUN::CMS2::Workspace
    Properties:
      WorkspaceName:
        Fn::Sub: ${CommonName}-ws
      DisplayName: Monitoring Center Workspace
      Description: Centralized monitoring workspace for metric aggregation
      SlsProject:
        Ref: SlsProject
  SourcePrometheusA:
    Type: ALIYUN::CMS2::PrometheusInstance
    Properties:
      PrometheusInstanceName:
        Fn::Sub: ${CommonName}-src-a
      StorageDuration:
        Ref: StorageDuration
      ArchiveDuration: 0
      PaymentType: POSTPAY
      EnableAuthFreeRead: true
      EnableAuthFreeWrite: false
      EnableAuthToken: true
      Workspace:
        Ref: Workspace
  SourcePrometheusB:
    Type: ALIYUN::CMS2::PrometheusInstance
    Properties:
      PrometheusInstanceName:
        Fn::Sub: ${CommonName}-src-b
      StorageDuration:
        Ref: StorageDuration
      ArchiveDuration: 0
      PaymentType: POSTPAY
      EnableAuthFreeRead: true
      EnableAuthFreeWrite: false
      EnableAuthToken: true
      Workspace:
        Ref: Workspace
  TargetPrometheus:
    Type: ALIYUN::CMS2::PrometheusInstance
    Properties:
      PrometheusInstanceName:
        Fn::Sub: ${CommonName}-target
      StorageDuration:
        Ref: StorageDuration
      ArchiveDuration: 365
      PaymentType: POSTPAY
      EnableAuthFreeRead: true
      EnableAuthFreeWrite: false
      EnableAuthToken: true
      Workspace:
        Ref: Workspace
  SystemMetricsAgg:
    Type: ALIYUN::CMS2::AggTaskGroup
    DependsOn:
      - SourcePrometheusA
      - TargetPrometheus
    Properties:
      AggTaskGroupName: system-metrics-agg
      InstanceId:
        Fn::GetAtt:
          - SourcePrometheusA
          - PrometheusInstanceId
      TargetPrometheusId:
        Fn::GetAtt:
          - TargetPrometheus
          - PrometheusInstanceId
      ScheduleMode: Cron
      CronExpr: 0/1 * * * *
      ScheduleTimeExpr: '@m'
      Delay: 30
      MaxRetries: 20
      MaxRunTimeInSeconds: 600
      OverrideIfExists: true
      Status: Running
      Description: Aggregate system-level metrics (CPU, memory, disk, network)
      AggTaskGroupConfig: |-
        groups:
          - name: cpu_rules
            interval: 1m
            rules:
              - record: job:node_cpu_usage:avg_rate5m
                expr: avg by (job) (rate(node_cpu_seconds_total{mode!="idle"}[5m]))
              - record: job:node_cpu_usage:max_rate5m
                expr: max by (job) (rate(node_cpu_seconds_total{mode!="idle"}[5m]))
              - record: instance:node_cpu_usage:rate5m
                expr: rate(node_cpu_seconds_total{mode!="idle"}[5m])
          - name: memory_rules
            interval: 1m
            rules:
              - record: job:node_memory_usage:avg
                expr: avg by (job) (node_memory_MemTotal_bytes - node_memory_MemAvailable_bytes)
              - record: job:node_memory_usage:percent
                expr: avg by (job) ((node_memory_MemTotal_bytes - node_memory_MemAvailable_bytes) / node_memory_MemTotal_bytes * 100)
              - record: job:node_memory_available:avg
                expr: avg by (job) (node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes * 100)
          - name: disk_rules
            interval: 1m
            rules:
              - record: job:node_disk_usage:percent
                expr: avg by (job) ((node_filesystem_size_bytes - node_filesystem_avail_bytes) / node_filesystem_size_bytes * 100)
              - record: job:node_disk_io:rate5m
                expr: avg by (job) (rate(node_disk_io_time_seconds_total[5m]))
          - name: network_rules
            interval: 1m
            rules:
              - record: job:node_network_receive:rate5m
                expr: avg by (job) (rate(node_network_receive_bytes_total[5m]))
              - record: job:node_network_transmit:rate5m
                expr: avg by (job) (rate(node_network_transmit_bytes_total[5m]))
      Tags:
        - Key: Category
          Value: SystemMetrics
        - Key: Environment
          Value: Production
        - Key: Team
          Value: SRE
  AppMetricsAgg:
    Type: ALIYUN::CMS2::AggTaskGroup
    DependsOn:
      - SourcePrometheusB
      - TargetPrometheus
    Properties:
      AggTaskGroupName: app-metrics-agg
      InstanceId:
        Fn::GetAtt:
          - SourcePrometheusB
          - PrometheusInstanceId
      TargetPrometheusId:
        Fn::GetAtt:
          - TargetPrometheus
          - PrometheusInstanceId
      ScheduleMode: FixedRate
      Delay: 60
      MaxRetries: 30
      MaxRunTimeInSeconds: 900
      OverrideIfExists: true
      Status: Running
      Description: Aggregate application-level metrics (HTTP requests, latency, errors)
      AggTaskGroupConfig: |-
        groups:
          - name: http_rules
            interval: 1m
            rules:
              - record: job:http_requests:rate5m
                expr: sum by (job) (rate(http_requests_total[5m]))
              - record: job:http_requests:error_rate5m
                expr: sum by (job) (rate(http_requests_total{status=~"5.."}[5m])) / sum by (job) (rate(http_requests_total[5m])) * 100
              - record: job:http_request_duration:p99
                expr: histogram_quantile(0.99, sum by (job, le) (rate(http_request_duration_seconds_bucket[5m])))
              - record: job:http_request_duration:p95
                expr: histogram_quantile(0.95, sum by (job, le) (rate(http_request_duration_seconds_bucket[5m])))
              - record: job:http_request_duration:avg
                expr: avg by (job) (rate(http_request_duration_seconds_sum[5m]) / rate(http_request_duration_seconds_count[5m]))
          - name: availability_rules
            interval: 1m
            rules:
              - record: job:up:avg_rate5m
                expr: avg by (job) (avg_over_time(up[5m]))
              - record: job:up:min_rate5m
                expr: min by (job) (avg_over_time(up[5m]))
      Tags:
        - Key: Category
          Value: AppMetrics
        - Key: Environment
          Value: Production
        - Key: Team
          Value: DevOps
Outputs:
  WorkspaceName:
    Description:
      zh-cn: Workspace name.
      en: Workspace name.
    Label:
      zh-cn: Workspace Name
      en: Workspace Name
    Value:
      Fn::GetAtt:
        - Workspace
        - WorkspaceName
  SystemMetricsAggId:
    Description:
      zh-cn: The ID of the system metrics aggregation task group.
      en: System metrics aggregation task group ID.
    Label:
      zh-cn: System Metrics Aggregation Task Group ID
      en: System Metrics Agg ID
    Value:
      Fn::GetAtt:
        - SystemMetricsAgg
        - AggTaskGroupId
  AppMetricsAggId:
    Description:
      zh-cn: The ID of the application metrics aggregation task group.
      en: App metrics aggregation task group ID.
    Label:
      zh-cn: Application Metrics Aggregation Task Group ID
      en: App Metrics Agg ID
    Value:
      Fn::GetAtt:
        - AppMetricsAgg
        - AggTaskGroupId
  TargetPrometheusId:
    Description:
      zh-cn: Target Prometheus instance ID.
      en: Target Prometheus instance ID.
    Label:
      zh-cn: Target Prometheus Instance ID
      en: Target Prometheus ID
    Value:
      Fn::GetAtt:
        - TargetPrometheus
        - PrometheusInstanceId
  TargetPrometheusRemoteWriteUrl:
    Description:
      zh-cn: The internal Remote Write URL of the target Prometheus instance.
      en: Target Prometheus instance Remote Write internal URL.
    Label:
      zh-cn: Target Prometheus Remote Write URL
      en: Target Prometheus Remote Write URL
    Value:
      Fn::GetAtt:
        - TargetPrometheus
        - RemoteWriteIntraUrl
  TargetPrometheusHttpApiUrl:
    Description:
      zh-cn: The internal HTTP API URL of the target Prometheus instance.
      en: Target Prometheus instance HTTP API internal URL.
    Label:
      zh-cn: Target Prometheus HTTP API URL
      en: Target Prometheus HTTP API URL
    Value:
      Fn::GetAtt:
        - TargetPrometheus
        - HttpApiIntraUrl
Metadata:
  ALIYUN::ROS::Interface:
    ParameterGroups:
      - Parameters:
          - CommonName
          - StorageDuration
          - SourcePrometheusCount
{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Description": {
    "zh-cn": "Create a complete monitoring data aggregation solution including an SLS log project, a CMS2 workspace, multiple Prometheus instance groups, and multiple aggregation task groups with recording rules of different granularities, enabling multidimensional monitoring data aggregation and centralized management.",
    "en": "Create a complete monitoring data aggregation solution including SLS log project, CMS2 workspace, multiple Prometheus instance groups, and multiple aggregation task groups with different granularity recording rules for multi-dimensional monitoring data aggregation and centralized management."
  },
  "Parameters": {
    "CommonName": {
      "Type": "String",
      "Label": {
        "zh-cn": "Resource Name Prefix",
        "en": "Resource Name Prefix"
      },
      "Description": {
        "zh-cn": "The common prefix for all resource names.",
        "en": "Unified name prefix for all resources."
      },
      "Default": "monitor-center",
      "MinLength": 1,
      "MaxLength": 50
    },
    "StorageDuration": {
      "Type": "Number",
      "Label": {
        "zh-cn": "Storage Duration (Days)",
        "en": "Storage Duration (Days)"
      },
      "Description": {
        "zh-cn": "The data retention period of the Prometheus instance.",
        "en": "Data storage duration of the Prometheus instance."
      },
      "AllowedValues": [
        15,
        30,
        60,
        90,
        180
      ],
      "Default": 90
    },
    "SourcePrometheusCount": {
      "Type": "Number",
      "Label": {
        "zh-cn": "Number of Source Prometheus Instances",
        "en": "Source Prometheus Instance Count"
      },
      "Description": {
        "zh-cn": "The number of source Prometheus instances to create.",
        "en": "Number of source Prometheus instances to create."
      },
      "AllowedValues": [
        1,
        2
      ],
      "Default": 2
    }
  },
  "Resources": {
    "SlsProject": {
      "Type": "ALIYUN::SLS::Project",
      "Properties": {
        "Name": {
          "Fn::Sub": "${CommonName}-sls"
        },
        "Description": "SLS project for monitoring workspace"
      }
    },
    "Workspace": {
      "Type": "ALIYUN::CMS2::Workspace",
      "Properties": {
        "WorkspaceName": {
          "Fn::Sub": "${CommonName}-ws"
        },
        "DisplayName": "Monitoring Center Workspace",
        "Description": "Centralized monitoring workspace for metric aggregation",
        "SlsProject": {
          "Ref": "SlsProject"
        }
      }
    },
    "SourcePrometheusA": {
      "Type": "ALIYUN::CMS2::PrometheusInstance",
      "Properties": {
        "PrometheusInstanceName": {
          "Fn::Sub": "${CommonName}-src-a"
        },
        "StorageDuration": {
          "Ref": "StorageDuration"
        },
        "ArchiveDuration": 0,
        "PaymentType": "POSTPAY",
        "EnableAuthFreeRead": true,
        "EnableAuthFreeWrite": false,
        "EnableAuthToken": true,
        "Workspace": {
          "Ref": "Workspace"
        }
      }
    },
    "SourcePrometheusB": {
      "Type": "ALIYUN::CMS2::PrometheusInstance",
      "Properties": {
        "PrometheusInstanceName": {
          "Fn::Sub": "${CommonName}-src-b"
        },
        "StorageDuration": {
          "Ref": "StorageDuration"
        },
        "ArchiveDuration": 0,
        "PaymentType": "POSTPAY",
        "EnableAuthFreeRead": true,
        "EnableAuthFreeWrite": false,
        "EnableAuthToken": true,
        "Workspace": {
          "Ref": "Workspace"
        }
      }
    },
    "TargetPrometheus": {
      "Type": "ALIYUN::CMS2::PrometheusInstance",
      "Properties": {
        "PrometheusInstanceName": {
          "Fn::Sub": "${CommonName}-target"
        },
        "StorageDuration": {
          "Ref": "StorageDuration"
        },
        "ArchiveDuration": 365,
        "PaymentType": "POSTPAY",
        "EnableAuthFreeRead": true,
        "EnableAuthFreeWrite": false,
        "EnableAuthToken": true,
        "Workspace": {
          "Ref": "Workspace"
        }
      }
    },
    "SystemMetricsAgg": {
      "Type": "ALIYUN::CMS2::AggTaskGroup",
      "DependsOn": [
        "SourcePrometheusA",
        "TargetPrometheus"
      ],
      "Properties": {
        "AggTaskGroupName": "system-metrics-agg",
        "InstanceId": {
          "Fn::GetAtt": [
            "SourcePrometheusA",
            "PrometheusInstanceId"
          ]
        },
        "TargetPrometheusId": {
          "Fn::GetAtt": [
            "TargetPrometheus",
            "PrometheusInstanceId"
          ]
        },
        "ScheduleMode": "Cron",
        "CronExpr": "0/1 * * * *",
        "ScheduleTimeExpr": "@m",
        "Delay": 30,
        "MaxRetries": 20,
        "MaxRunTimeInSeconds": 600,
        "OverrideIfExists": true,
        "Status": "Running",
        "Description": "Aggregate system-level metrics (CPU, memory, disk, network)",
        "AggTaskGroupConfig": "groups:\n  - name: cpu_rules\n    interval: 1m\n    rules:\n      - record: job:node_cpu_usage:avg_rate5m\n        expr: avg by (job) (rate(node_cpu_seconds_total{mode!=\"idle\"}[5m]))\n      - record: job:node_cpu_usage:max_rate5m\n        expr: max by (job) (rate(node_cpu_seconds_total{mode!=\"idle\"}[5m]))\n      - record: instance:node_cpu_usage:rate5m\n        expr: rate(node_cpu_seconds_total{mode!=\"idle\"}[5m])\n  - name: memory_rules\n    interval: 1m\n    rules:\n      - record: job:node_memory_usage:avg\n        expr: avg by (job) (node_memory_MemTotal_bytes - node_memory_MemAvailable_bytes)\n      - record: job:node_memory_usage:percent\n        expr: avg by (job) ((node_memory_MemTotal_bytes - node_memory_MemAvailable_bytes) / node_memory_MemTotal_bytes * 100)\n      - record: job:node_memory_available:avg\n        expr: avg by (job) (node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes * 100)\n  - name: disk_rules\n    interval: 1m\n    rules:\n      - record: job:node_disk_usage:percent\n        expr: avg by (job) ((node_filesystem_size_bytes - node_filesystem_avail_bytes) / node_filesystem_size_bytes * 100)\n      - record: job:node_disk_io:rate5m\n        expr: avg by (job) (rate(node_disk_io_time_seconds_total[5m]))\n  - name: network_rules\n    interval: 1m\n    rules:\n      - record: job:node_network_receive:rate5m\n        expr: avg by (job) (rate(node_network_receive_bytes_total[5m]))\n      - record: job:node_network_transmit:rate5m\n        expr: avg by (job) (rate(node_network_transmit_bytes_total[5m]))",
        "Tags": [
          {
            "Key": "Category",
            "Value": "SystemMetrics"
          },
          {
            "Key": "Environment",
            "Value": "Production"
          },
          {
            "Key": "Team",
            "Value": "SRE"
          }
        ]
      }
    },
    "AppMetricsAgg": {
      "Type": "ALIYUN::CMS2::AggTaskGroup",
      "DependsOn": [
        "SourcePrometheusB",
        "TargetPrometheus"
      ],
      "Properties": {
        "AggTaskGroupName": "app-metrics-agg",
        "InstanceId": {
          "Fn::GetAtt": [
            "SourcePrometheusB",
            "PrometheusInstanceId"
          ]
        },
        "TargetPrometheusId": {
          "Fn::GetAtt": [
            "TargetPrometheus",
            "PrometheusInstanceId"
          ]
        },
        "ScheduleMode": "FixedRate",
        "Delay": 60,
        "MaxRetries": 30,
        "MaxRunTimeInSeconds": 900,
        "OverrideIfExists": true,
        "Status": "Running",
        "Description": "Aggregate application-level metrics (HTTP requests, latency, errors)",
        "AggTaskGroupConfig": "groups:\n  - name: http_rules\n    interval: 1m\n    rules:\n      - record: job:http_requests:rate5m\n        expr: sum by (job) (rate(http_requests_total[5m]))\n      - record: job:http_requests:error_rate5m\n        expr: sum by (job) (rate(http_requests_total{status=~\"5..\"}[5m])) / sum by (job) (rate(http_requests_total[5m])) * 100\n      - record: job:http_request_duration:p99\n        expr: histogram_quantile(0.99, sum by (job, le) (rate(http_request_duration_seconds_bucket[5m])))\n      - record: job:http_request_duration:p95\n        expr: histogram_quantile(0.95, sum by (job, le) (rate(http_request_duration_seconds_bucket[5m])))\n      - record: job:http_request_duration:avg\n        expr: avg by (job) (rate(http_request_duration_seconds_sum[5m]) / rate(http_request_duration_seconds_count[5m]))\n  - name: availability_rules\n    interval: 1m\n    rules:\n      - record: job:up:avg_rate5m\n        expr: avg by (job) (avg_over_time(up[5m]))\n      - record: job:up:min_rate5m\n        expr: min by (job) (avg_over_time(up[5m]))",
        "Tags": [
          {
            "Key": "Category",
            "Value": "AppMetrics"
          },
          {
            "Key": "Environment",
            "Value": "Production"
          },
          {
            "Key": "Team",
            "Value": "DevOps"
          }
        ]
      }
    }
  },
  "Outputs": {
    "WorkspaceName": {
      "Description": {
        "zh-cn": "Workspace name.",
        "en": "Workspace name."
      },
      "Label": {
        "zh-cn": "Workspace Name",
        "en": "Workspace Name"
      },
      "Value": {
        "Fn::GetAtt": [
          "Workspace",
          "WorkspaceName"
        ]
      }
    },
    "SystemMetricsAggId": {
      "Description": {
        "zh-cn": "The ID of the system metrics aggregation task group.",
        "en": "System metrics aggregation task group ID."
      },
      "Label": {
        "zh-cn": "System Metrics Aggregation Task Group ID",
        "en": "System Metrics Agg ID"
      },
      "Value": {
        "Fn::GetAtt": [
          "SystemMetricsAgg",
          "AggTaskGroupId"
        ]
      }
    },
    "AppMetricsAggId": {
      "Description": {
        "zh-cn": "The ID of the application metrics aggregation task group.",
        "en": "App metrics aggregation task group ID."
      },
      "Label": {
        "zh-cn": "Application Metrics Aggregation Task Group ID",
        "en": "App Metrics Agg ID"
      },
      "Value": {
        "Fn::GetAtt": [
          "AppMetricsAgg",
          "AggTaskGroupId"
        ]
      }
    },
    "TargetPrometheusId": {
      "Description": {
        "zh-cn": "Target Prometheus instance ID.",
        "en": "Target Prometheus instance ID."
      },
      "Label": {
        "zh-cn": "Target Prometheus Instance ID",
        "en": "Target Prometheus ID"
      },
      "Value": {
        "Fn::GetAtt": [
          "TargetPrometheus",
          "PrometheusInstanceId"
        ]
      }
    },
    "TargetPrometheusRemoteWriteUrl": {
      "Description": {
        "zh-cn": "The internal Remote Write URL of the target Prometheus instance.",
        "en": "Target Prometheus instance Remote Write internal URL."
      },
      "Label": {
        "zh-cn": "Target Prometheus Remote Write URL",
        "en": "Target Prometheus Remote Write URL"
      },
      "Value": {
        "Fn::GetAtt": [
          "TargetPrometheus",
          "RemoteWriteIntraUrl"
        ]
      }
    },
    "TargetPrometheusHttpApiUrl": {
      "Description": {
        "zh-cn": "The internal HTTP API URL of the target Prometheus instance.",
        "en": "Target Prometheus instance HTTP API internal URL."
      },
      "Label": {
        "zh-cn": "Target Prometheus HTTP API URL",
        "en": "Target Prometheus HTTP API URL"
      },
      "Value": {
        "Fn::GetAtt": [
          "TargetPrometheus",
          "HttpApiIntraUrl"
        ]
      }
    }
  },
  "Metadata": {
    "ALIYUN::ROS::Interface": {
      "ParameterGroups": [
        {
          "Parameters": [
            "CommonName",
            "StorageDuration",
            "SourcePrometheusCount"
          ]
        }
      ]
    }
  }
}