ALIYUN::CMS2::Workspace

更新时间:
复制 MD 格式

ALIYUN::CMS2::Workspace类型用于创建工作空间。

语法

{
  "Type": "ALIYUN::CMS2::Workspace",
  "Properties": {
    "SlsProject": String,
    "WorkspaceName": String,
    "Description": String,
    "DisplayName": String
  }
}

属性

属性名称

类型

必须

允许更新

描述

约束

SlsProject

String

是

否

日志服务(SLS)项目的名称。

无

WorkspaceName

String

是

否

工作空间的名称。

无

Description

String

否

是

工作空间的描述。

无

DisplayName

String

否

是

工作空间的显示名称。

无

返回值

Fn::GetAtt

  • WorkspaceName:工作空间的名称。

示例

场景 1 :基于已有 SLS 项目创建工作空间

ROSTemplateFormatVersion: '2015-09-01'
Description:
  zh-cn: 基于已有的SLS日志项目创建一个简单的CMS2工作空间。
  en: Create a simple CMS2 workspace based on an existing SLS log project.
Parameters:
  WorkspaceName:
    Type: String
    Label:
      zh-cn: 工作空间名称
      en: Workspace Name
    Description:
      zh-cn: CMS2工作空间的名称,1-56个字符。
      en: The name of the CMS2 workspace, 1-56 characters.
    MinLength: 1
    MaxLength: 56
    Default: my-workspace
  SlsProjectName:
    Type: String
    Label:
      zh-cn: SLS项目名称
      en: SLS Project Name
    Description:
      zh-cn: 已有的SLS日志项目名称,工作空间将关联此项目。
      en: The name of an existing SLS log project to associate with the workspace.
Resources:
  Workspace:
    Type: ALIYUN::CMS2::Workspace
    Properties:
      WorkspaceName:
        Ref: WorkspaceName
      SlsProject:
        Ref: SlsProjectName
      DisplayName: My Monitoring Workspace
      Description: Simple CMS2 workspace
Outputs:
  WorkspaceName:
    Description:
      zh-cn: 工作空间名称。
      en: Workspace name.
    Label:
      zh-cn: 工作空间名称
      en: Workspace Name
    Value:
      Fn::GetAtt:
        - Workspace
        - WorkspaceName
Metadata:
  ALIYUN::ROS::Interface:
    ParameterGroups:
      - Parameters:
          - WorkspaceName
          - SlsProjectName
{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Description": {
    "zh-cn": "基于已有的SLS日志项目创建一个简单的CMS2工作空间。",
    "en": "Create a simple CMS2 workspace based on an existing SLS log project."
  },
  "Parameters": {
    "WorkspaceName": {
      "Type": "String",
      "Label": {
        "zh-cn": "工作空间名称",
        "en": "Workspace Name"
      },
      "Description": {
        "zh-cn": "CMS2工作空间的名称,1-56个字符。",
        "en": "The name of the CMS2 workspace, 1-56 characters."
      },
      "MinLength": 1,
      "MaxLength": 56,
      "Default": "my-workspace"
    },
    "SlsProjectName": {
      "Type": "String",
      "Label": {
        "zh-cn": "SLS项目名称",
        "en": "SLS Project Name"
      },
      "Description": {
        "zh-cn": "已有的SLS日志项目名称,工作空间将关联此项目。",
        "en": "The name of an existing SLS log project to associate with the workspace."
      }
    }
  },
  "Resources": {
    "Workspace": {
      "Type": "ALIYUN::CMS2::Workspace",
      "Properties": {
        "WorkspaceName": {
          "Ref": "WorkspaceName"
        },
        "SlsProject": {
          "Ref": "SlsProjectName"
        },
        "DisplayName": "My Monitoring Workspace",
        "Description": "Simple CMS2 workspace"
      }
    }
  },
  "Outputs": {
    "WorkspaceName": {
      "Description": {
        "zh-cn": "工作空间名称。",
        "en": "Workspace name."
      },
      "Label": {
        "zh-cn": "工作空间名称",
        "en": "Workspace Name"
      },
      "Value": {
        "Fn::GetAtt": [
          "Workspace",
          "WorkspaceName"
        ]
      }
    }
  },
  "Metadata": {
    "ALIYUN::ROS::Interface": {
      "ParameterGroups": [
        {
          "Parameters": [
            "WorkspaceName",
            "SlsProjectName"
          ]
        }
      ]
    }
  }
}

场景 2 :创建 SLS 项目、工作空间、Prometheus 实例

ROSTemplateFormatVersion: '2015-09-01'
Description:
  zh-cn: 创建SLS日志项目和CMS2工作空间,并在工作空间下创建Prometheus实例,实现监控数据的采集与存储。
  en: Create an SLS log project and CMS2 workspace, then create a Prometheus instance under the workspace for monitoring data collection and storage.
Parameters:
  CommonName:
    Type: String
    Label:
      zh-cn: 资源名称前缀
      en: Resource Name Prefix
    Description:
      zh-cn: 所有资源名称的统一前缀。
      en: Unified name prefix for all resources.
    Default: monitoring
    MinLength: 1
    MaxLength: 50
  StorageDuration:
    Type: Number
    Label:
      zh-cn: Prometheus存储时长(天)
      en: Prometheus Storage Duration (Days)
    Description:
      zh-cn: Prometheus实例的数据存储时长。
      en: Data storage duration of the Prometheus instance.
    AllowedValues:
      - 15
      - 30
      - 60
      - 90
      - 180
    Default: 90
  DataRedundancyType:
    Type: String
    Label:
      zh-cn: SLS数据容灾类型
      en: SLS Data Redundancy Type
    Description:
      zh-cn: SLS项目的数据容灾类型。
      en: Data redundancy type of the SLS project.
    AllowedValues:
      - LRS
      - ZRS
    Default: LRS
Resources:
  SlsProject:
    Type: ALIYUN::SLS::Project
    Properties:
      Name:
        Fn::Sub: ${CommonName}-sls
      Description: SLS project for monitoring workspace
      DataRedundancyType:
        Ref: DataRedundancyType
      Tags:
        - Key: Purpose
          Value: Monitoring
        - Key: CreatedBy
          Value: ROS
  Workspace:
    Type: ALIYUN::CMS2::Workspace
    Properties:
      WorkspaceName:
        Fn::Sub: ${CommonName}-ws
      DisplayName:
        Fn::Sub: ${CommonName} Monitoring Workspace
      Description: Monitoring workspace with Prometheus instance
      SlsProject:
        Ref: SlsProject
  PrometheusInstance:
    Type: ALIYUN::CMS2::PrometheusInstance
    Properties:
      PrometheusInstanceName:
        Fn::Sub: ${CommonName}-prometheus
      StorageDuration:
        Ref: StorageDuration
      ArchiveDuration: 0
      PaymentType: POSTPAY
      EnableAuthFreeRead: true
      EnableAuthFreeWrite: false
      EnableAuthToken: true
      Workspace:
        Ref: Workspace
Outputs:
  WorkspaceName:
    Description:
      zh-cn: 工作空间名称。
      en: Workspace name.
    Label:
      zh-cn: 工作空间名称
      en: Workspace Name
    Value:
      Fn::GetAtt:
        - Workspace
        - WorkspaceName
  PrometheusInstanceId:
    Description:
      zh-cn: Prometheus实例ID。
      en: Prometheus instance ID.
    Label:
      zh-cn: Prometheus实例ID
      en: Prometheus Instance ID
    Value:
      Fn::GetAtt:
        - PrometheusInstance
        - PrometheusInstanceId
  PrometheusRemoteWriteUrl:
    Description:
      zh-cn: Prometheus Remote Write内网地址。
      en: Prometheus Remote Write internal URL.
    Label:
      zh-cn: Remote Write地址
      en: Remote Write URL
    Value:
      Fn::GetAtt:
        - PrometheusInstance
        - RemoteWriteIntraUrl
  PrometheusHttpApiUrl:
    Description:
      zh-cn: Prometheus HTTP API内网地址。
      en: Prometheus HTTP API internal URL.
    Label:
      zh-cn: HTTP API地址
      en: HTTP API URL
    Value:
      Fn::GetAtt:
        - PrometheusInstance
        - HttpApiIntraUrl
Metadata:
  ALIYUN::ROS::Interface:
    ParameterGroups:
      - Parameters:
          - CommonName
          - StorageDuration
          - DataRedundancyType
{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Description": {
    "zh-cn": "创建SLS日志项目和CMS2工作空间,并在工作空间下创建Prometheus实例,实现监控数据的采集与存储。",
    "en": "Create an SLS log project and CMS2 workspace, then create a Prometheus instance under the workspace for monitoring data collection and storage."
  },
  "Parameters": {
    "CommonName": {
      "Type": "String",
      "Label": {
        "zh-cn": "资源名称前缀",
        "en": "Resource Name Prefix"
      },
      "Description": {
        "zh-cn": "所有资源名称的统一前缀。",
        "en": "Unified name prefix for all resources."
      },
      "Default": "monitoring",
      "MinLength": 1,
      "MaxLength": 50
    },
    "StorageDuration": {
      "Type": "Number",
      "Label": {
        "zh-cn": "Prometheus存储时长(天)",
        "en": "Prometheus Storage Duration (Days)"
      },
      "Description": {
        "zh-cn": "Prometheus实例的数据存储时长。",
        "en": "Data storage duration of the Prometheus instance."
      },
      "AllowedValues": [
        15,
        30,
        60,
        90,
        180
      ],
      "Default": 90
    },
    "DataRedundancyType": {
      "Type": "String",
      "Label": {
        "zh-cn": "SLS数据容灾类型",
        "en": "SLS Data Redundancy Type"
      },
      "Description": {
        "zh-cn": "SLS项目的数据容灾类型。",
        "en": "Data redundancy type of the SLS project."
      },
      "AllowedValues": [
        "LRS",
        "ZRS"
      ],
      "Default": "LRS"
    }
  },
  "Resources": {
    "SlsProject": {
      "Type": "ALIYUN::SLS::Project",
      "Properties": {
        "Name": {
          "Fn::Sub": "${CommonName}-sls"
        },
        "Description": "SLS project for monitoring workspace",
        "DataRedundancyType": {
          "Ref": "DataRedundancyType"
        },
        "Tags": [
          {
            "Key": "Purpose",
            "Value": "Monitoring"
          },
          {
            "Key": "CreatedBy",
            "Value": "ROS"
          }
        ]
      }
    },
    "Workspace": {
      "Type": "ALIYUN::CMS2::Workspace",
      "Properties": {
        "WorkspaceName": {
          "Fn::Sub": "${CommonName}-ws"
        },
        "DisplayName": {
          "Fn::Sub": "${CommonName} Monitoring Workspace"
        },
        "Description": "Monitoring workspace with Prometheus instance",
        "SlsProject": {
          "Ref": "SlsProject"
        }
      }
    },
    "PrometheusInstance": {
      "Type": "ALIYUN::CMS2::PrometheusInstance",
      "Properties": {
        "PrometheusInstanceName": {
          "Fn::Sub": "${CommonName}-prometheus"
        },
        "StorageDuration": {
          "Ref": "StorageDuration"
        },
        "ArchiveDuration": 0,
        "PaymentType": "POSTPAY",
        "EnableAuthFreeRead": true,
        "EnableAuthFreeWrite": false,
        "EnableAuthToken": true,
        "Workspace": {
          "Ref": "Workspace"
        }
      }
    }
  },
  "Outputs": {
    "WorkspaceName": {
      "Description": {
        "zh-cn": "工作空间名称。",
        "en": "Workspace name."
      },
      "Label": {
        "zh-cn": "工作空间名称",
        "en": "Workspace Name"
      },
      "Value": {
        "Fn::GetAtt": [
          "Workspace",
          "WorkspaceName"
        ]
      }
    },
    "PrometheusInstanceId": {
      "Description": {
        "zh-cn": "Prometheus实例ID。",
        "en": "Prometheus instance ID."
      },
      "Label": {
        "zh-cn": "Prometheus实例ID",
        "en": "Prometheus Instance ID"
      },
      "Value": {
        "Fn::GetAtt": [
          "PrometheusInstance",
          "PrometheusInstanceId"
        ]
      }
    },
    "PrometheusRemoteWriteUrl": {
      "Description": {
        "zh-cn": "Prometheus Remote Write内网地址。",
        "en": "Prometheus Remote Write internal URL."
      },
      "Label": {
        "zh-cn": "Remote Write地址",
        "en": "Remote Write URL"
      },
      "Value": {
        "Fn::GetAtt": [
          "PrometheusInstance",
          "RemoteWriteIntraUrl"
        ]
      }
    },
    "PrometheusHttpApiUrl": {
      "Description": {
        "zh-cn": "Prometheus HTTP API内网地址。",
        "en": "Prometheus HTTP API internal URL."
      },
      "Label": {
        "zh-cn": "HTTP API地址",
        "en": "HTTP API URL"
      },
      "Value": {
        "Fn::GetAtt": [
          "PrometheusInstance",
          "HttpApiIntraUrl"
        ]
      }
    }
  },
  "Metadata": {
    "ALIYUN::ROS::Interface": {
      "ParameterGroups": [
        {
          "Parameters": [
            "CommonName",
            "StorageDuration",
            "DataRedundancyType"
          ]
        }
      ]
    }
  }
}

场景 3 :创建全量版监控中心方案

ROSTemplateFormatVersion: '2015-09-01'
Description:
  zh-cn: 创建完整的监控中心方案,包含SLS日志项目、CMS2工作空间、多个Prometheus实例(系统/应用分离)、APM和RUM可观测服务、聚合任务组(Recording Rule),实现全链路监控数据采集、存储、聚合与分析。
  en: Create a complete monitoring center solution including SLS log project, CMS2 workspace, multiple Prometheus instances (system/app separated), APM and RUM observability services, and aggregation task groups with recording rules for full-stack monitoring data collection, storage, aggregation and analysis.
Parameters:
  CommonName:
    Type: String
    Label:
      zh-cn: 资源名称前缀
      en: Resource Name Prefix
    Description:
      zh-cn: 所有资源名称的统一前缀。
      en: Unified name prefix for all resources.
    Default: monitor-center
    MinLength: 1
    MaxLength: 50
  StorageDuration:
    Type: Number
    Label:
      zh-cn: Prometheus存储时长(天)
      en: Prometheus Storage Duration (Days)
    Description:
      zh-cn: Prometheus实例的数据存储时长。
      en: Data storage duration of the Prometheus instance.
    AllowedValues:
      - 15
      - 30
      - 60
      - 90
      - 180
    Default: 90
  DataRedundancyType:
    Type: String
    Label:
      zh-cn: SLS数据容灾类型
      en: SLS Data Redundancy Type
    Description:
      zh-cn: SLS项目的数据容灾类型。
      en: Data redundancy type of the SLS project.
    AllowedValues:
      - LRS
      - ZRS
    Default: ZRS
  EnableApm:
    Type: String
    Label:
      zh-cn: 是否启用APM可观测
      en: Enable APM Observability
    Description:
      zh-cn: 是否在工作空间下启用APM应用性能监控。
      en: Whether to enable APM application performance monitoring in the workspace.
    AllowedValues:
      - 'true'
      - 'false'
    Default: 'true'
  EnableRum:
    Type: String
    Label:
      zh-cn: 是否启用RUM可观测
      en: Enable RUM Observability
    Description:
      zh-cn: 是否在工作空间下启用RUM真实用户监控。
      en: Whether to enable RUM real user monitoring in the workspace.
    AllowedValues:
      - 'true'
      - 'false'
    Default: 'true'
Conditions:
  CreateApm:
    Fn::Equals:
      - Ref: EnableApm
      - 'true'
  CreateRum:
    Fn::Equals:
      - Ref: EnableRum
      - 'true'
Resources:
  SlsProject:
    Type: ALIYUN::SLS::Project
    Properties:
      Name:
        Fn::Sub: ${CommonName}-sls
      Description: SLS project for monitoring center workspace
      DataRedundancyType:
        Ref: DataRedundancyType
      Tags:
        - Key: Purpose
          Value: MonitoringCenter
        - Key: CreatedBy
          Value: ROS
        - Key: Environment
          Value: Production
  Workspace:
    Type: ALIYUN::CMS2::Workspace
    Properties:
      WorkspaceName:
        Fn::Sub: ${CommonName}-ws
      DisplayName:
        Fn::Sub: ${CommonName} Monitoring Center
      Description: Centralized monitoring workspace with full observability stack
      SlsProject:
        Ref: SlsProject
  SystemPrometheus:
    Type: ALIYUN::CMS2::PrometheusInstance
    Properties:
      PrometheusInstanceName:
        Fn::Sub: ${CommonName}-sys-prom
      StorageDuration:
        Ref: StorageDuration
      ArchiveDuration: 0
      PaymentType: POSTPAY
      EnableAuthFreeRead: true
      EnableAuthFreeWrite: false
      EnableAuthToken: true
      Workspace:
        Ref: Workspace
  AppPrometheus:
    Type: ALIYUN::CMS2::PrometheusInstance
    Properties:
      PrometheusInstanceName:
        Fn::Sub: ${CommonName}-app-prom
      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-prom
      StorageDuration:
        Ref: StorageDuration
      ArchiveDuration: 365
      PaymentType: POSTPAY
      EnableAuthFreeRead: true
      EnableAuthFreeWrite: false
      EnableAuthToken: true
      Workspace:
        Ref: Workspace
  ApmObservability:
    Type: ALIYUN::CMS2::ServiceObservability
    Condition: CreateApm
    Properties:
      Workspace:
        Ref: Workspace
      Type: apm
  RumObservability:
    Type: ALIYUN::CMS2::ServiceObservability
    Condition: CreateRum
    Properties:
      Workspace:
        Ref: Workspace
      Type: rum
  SystemMetricsAgg:
    Type: ALIYUN::CMS2::AggTaskGroup
    DependsOn:
      - SystemPrometheus
      - TargetPrometheus
    Properties:
      AggTaskGroupName: system-metrics-agg
      InstanceId:
        Fn::GetAtt:
          - SystemPrometheus
          - 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]))
          - name: memory_rules
            interval: 1m
            rules:
              - record: job:node_memory_usage:percent
                expr: avg by (job) ((node_memory_MemTotal_bytes - node_memory_MemAvailable_bytes) / node_memory_MemTotal_bytes * 100)
          - name: disk_network_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_network_receive:rate5m
                expr: avg by (job) (rate(node_network_receive_bytes_total[5m]))
      Tags:
        - Key: Category
          Value: SystemMetrics
        - Key: Team
          Value: SRE
  AppMetricsAgg:
    Type: ALIYUN::CMS2::AggTaskGroup
    DependsOn:
      - AppPrometheus
      - TargetPrometheus
    Properties:
      AggTaskGroupName: app-metrics-agg
      InstanceId:
        Fn::GetAtt:
          - AppPrometheus
          - 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])))
          - name: availability_rules
            interval: 1m
            rules:
              - record: job:up:avg_rate5m
                expr: avg by (job) (avg_over_time(up[5m]))
      Tags:
        - Key: Category
          Value: AppMetrics
        - Key: Team
          Value: DevOps
Outputs:
  WorkspaceName:
    Description:
      zh-cn: 工作空间名称。
      en: Workspace name.
    Label:
      zh-cn: 工作空间名称
      en: Workspace Name
    Value:
      Fn::GetAtt:
        - Workspace
        - WorkspaceName
  SystemPrometheusId:
    Description:
      zh-cn: 系统指标Prometheus实例ID。
      en: System metrics Prometheus instance ID.
    Label:
      zh-cn: 系统Prometheus实例ID
      en: System Prometheus ID
    Value:
      Fn::GetAtt:
        - SystemPrometheus
        - PrometheusInstanceId
  AppPrometheusId:
    Description:
      zh-cn: 应用指标Prometheus实例ID。
      en: App metrics Prometheus instance ID.
    Label:
      zh-cn: 应用Prometheus实例ID
      en: App Prometheus ID
    Value:
      Fn::GetAtt:
        - AppPrometheus
        - PrometheusInstanceId
  TargetPrometheusId:
    Description:
      zh-cn: 目标Prometheus实例ID。
      en: Target Prometheus instance ID.
    Label:
      zh-cn: 目标Prometheus实例ID
      en: Target Prometheus ID
    Value:
      Fn::GetAtt:
        - TargetPrometheus
        - PrometheusInstanceId
  TargetPrometheusRemoteWriteUrl:
    Description:
      zh-cn: 目标Prometheus实例Remote Write内网地址。
      en: Target Prometheus instance Remote Write internal URL.
    Label:
      zh-cn: 目标Prometheus Remote Write地址
      en: Target Prometheus Remote Write URL
    Value:
      Fn::GetAtt:
        - TargetPrometheus
        - RemoteWriteIntraUrl
  TargetPrometheusHttpApiUrl:
    Description:
      zh-cn: 目标Prometheus实例HTTP API内网地址。
      en: Target Prometheus instance HTTP API internal URL.
    Label:
      zh-cn: 目标Prometheus HTTP API地址
      en: Target Prometheus HTTP API URL
    Value:
      Fn::GetAtt:
        - TargetPrometheus
        - HttpApiIntraUrl
  SystemMetricsAggId:
    Description:
      zh-cn: 系统指标聚合任务组ID。
      en: System metrics aggregation task group ID.
    Label:
      zh-cn: 系统指标聚合任务组ID
      en: System Metrics Agg ID
    Value:
      Fn::GetAtt:
        - SystemMetricsAgg
        - AggTaskGroupId
  AppMetricsAggId:
    Description:
      zh-cn: 应用指标聚合任务组ID。
      en: App metrics aggregation task group ID.
    Label:
      zh-cn: 应用指标聚合任务组ID
      en: App Metrics Agg ID
    Value:
      Fn::GetAtt:
        - AppMetricsAgg
        - AggTaskGroupId
Metadata:
  ALIYUN::ROS::Interface:
    ParameterGroups:
      - Parameters:
          - CommonName
          - StorageDuration
          - DataRedundancyType
      - Parameters:
          - EnableApm
          - EnableRum
{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Description": {
    "zh-cn": "创建完整的监控中心方案,包含SLS日志项目、CMS2工作空间、多个Prometheus实例(系统/应用分离)、APM和RUM可观测服务、聚合任务组(Recording Rule),实现全链路监控数据采集、存储、聚合与分析。",
    "en": "Create a complete monitoring center solution including SLS log project, CMS2 workspace, multiple Prometheus instances (system/app separated), APM and RUM observability services, and aggregation task groups with recording rules for full-stack monitoring data collection, storage, aggregation and analysis."
  },
  "Parameters": {
    "CommonName": {
      "Type": "String",
      "Label": {
        "zh-cn": "资源名称前缀",
        "en": "Resource Name Prefix"
      },
      "Description": {
        "zh-cn": "所有资源名称的统一前缀。",
        "en": "Unified name prefix for all resources."
      },
      "Default": "monitor-center",
      "MinLength": 1,
      "MaxLength": 50
    },
    "StorageDuration": {
      "Type": "Number",
      "Label": {
        "zh-cn": "Prometheus存储时长(天)",
        "en": "Prometheus Storage Duration (Days)"
      },
      "Description": {
        "zh-cn": "Prometheus实例的数据存储时长。",
        "en": "Data storage duration of the Prometheus instance."
      },
      "AllowedValues": [
        15,
        30,
        60,
        90,
        180
      ],
      "Default": 90
    },
    "DataRedundancyType": {
      "Type": "String",
      "Label": {
        "zh-cn": "SLS数据容灾类型",
        "en": "SLS Data Redundancy Type"
      },
      "Description": {
        "zh-cn": "SLS项目的数据容灾类型。",
        "en": "Data redundancy type of the SLS project."
      },
      "AllowedValues": [
        "LRS",
        "ZRS"
      ],
      "Default": "ZRS"
    },
    "EnableApm": {
      "Type": "String",
      "Label": {
        "zh-cn": "是否启用APM可观测",
        "en": "Enable APM Observability"
      },
      "Description": {
        "zh-cn": "是否在工作空间下启用APM应用性能监控。",
        "en": "Whether to enable APM application performance monitoring in the workspace."
      },
      "AllowedValues": [
        "true",
        "false"
      ],
      "Default": "true"
    },
    "EnableRum": {
      "Type": "String",
      "Label": {
        "zh-cn": "是否启用RUM可观测",
        "en": "Enable RUM Observability"
      },
      "Description": {
        "zh-cn": "是否在工作空间下启用RUM真实用户监控。",
        "en": "Whether to enable RUM real user monitoring in the workspace."
      },
      "AllowedValues": [
        "true",
        "false"
      ],
      "Default": "true"
    }
  },
  "Conditions": {
    "CreateApm": {
      "Fn::Equals": [
        {
          "Ref": "EnableApm"
        },
        "true"
      ]
    },
    "CreateRum": {
      "Fn::Equals": [
        {
          "Ref": "EnableRum"
        },
        "true"
      ]
    }
  },
  "Resources": {
    "SlsProject": {
      "Type": "ALIYUN::SLS::Project",
      "Properties": {
        "Name": {
          "Fn::Sub": "${CommonName}-sls"
        },
        "Description": "SLS project for monitoring center workspace",
        "DataRedundancyType": {
          "Ref": "DataRedundancyType"
        },
        "Tags": [
          {
            "Key": "Purpose",
            "Value": "MonitoringCenter"
          },
          {
            "Key": "CreatedBy",
            "Value": "ROS"
          },
          {
            "Key": "Environment",
            "Value": "Production"
          }
        ]
      }
    },
    "Workspace": {
      "Type": "ALIYUN::CMS2::Workspace",
      "Properties": {
        "WorkspaceName": {
          "Fn::Sub": "${CommonName}-ws"
        },
        "DisplayName": {
          "Fn::Sub": "${CommonName} Monitoring Center"
        },
        "Description": "Centralized monitoring workspace with full observability stack",
        "SlsProject": {
          "Ref": "SlsProject"
        }
      }
    },
    "SystemPrometheus": {
      "Type": "ALIYUN::CMS2::PrometheusInstance",
      "Properties": {
        "PrometheusInstanceName": {
          "Fn::Sub": "${CommonName}-sys-prom"
        },
        "StorageDuration": {
          "Ref": "StorageDuration"
        },
        "ArchiveDuration": 0,
        "PaymentType": "POSTPAY",
        "EnableAuthFreeRead": true,
        "EnableAuthFreeWrite": false,
        "EnableAuthToken": true,
        "Workspace": {
          "Ref": "Workspace"
        }
      }
    },
    "AppPrometheus": {
      "Type": "ALIYUN::CMS2::PrometheusInstance",
      "Properties": {
        "PrometheusInstanceName": {
          "Fn::Sub": "${CommonName}-app-prom"
        },
        "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-prom"
        },
        "StorageDuration": {
          "Ref": "StorageDuration"
        },
        "ArchiveDuration": 365,
        "PaymentType": "POSTPAY",
        "EnableAuthFreeRead": true,
        "EnableAuthFreeWrite": false,
        "EnableAuthToken": true,
        "Workspace": {
          "Ref": "Workspace"
        }
      }
    },
    "ApmObservability": {
      "Type": "ALIYUN::CMS2::ServiceObservability",
      "Condition": "CreateApm",
      "Properties": {
        "Workspace": {
          "Ref": "Workspace"
        },
        "Type": "apm"
      }
    },
    "RumObservability": {
      "Type": "ALIYUN::CMS2::ServiceObservability",
      "Condition": "CreateRum",
      "Properties": {
        "Workspace": {
          "Ref": "Workspace"
        },
        "Type": "rum"
      }
    },
    "SystemMetricsAgg": {
      "Type": "ALIYUN::CMS2::AggTaskGroup",
      "DependsOn": [
        "SystemPrometheus",
        "TargetPrometheus"
      ],
      "Properties": {
        "AggTaskGroupName": "system-metrics-agg",
        "InstanceId": {
          "Fn::GetAtt": [
            "SystemPrometheus",
            "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  - name: memory_rules\n    interval: 1m\n    rules:\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  - name: disk_network_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_network_receive:rate5m\n        expr: avg by (job) (rate(node_network_receive_bytes_total[5m]))",
        "Tags": [
          {
            "Key": "Category",
            "Value": "SystemMetrics"
          },
          {
            "Key": "Team",
            "Value": "SRE"
          }
        ]
      }
    },
    "AppMetricsAgg": {
      "Type": "ALIYUN::CMS2::AggTaskGroup",
      "DependsOn": [
        "AppPrometheus",
        "TargetPrometheus"
      ],
      "Properties": {
        "AggTaskGroupName": "app-metrics-agg",
        "InstanceId": {
          "Fn::GetAtt": [
            "AppPrometheus",
            "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  - name: availability_rules\n    interval: 1m\n    rules:\n      - record: job:up:avg_rate5m\n        expr: avg by (job) (avg_over_time(up[5m]))",
        "Tags": [
          {
            "Key": "Category",
            "Value": "AppMetrics"
          },
          {
            "Key": "Team",
            "Value": "DevOps"
          }
        ]
      }
    }
  },
  "Outputs": {
    "WorkspaceName": {
      "Description": {
        "zh-cn": "工作空间名称。",
        "en": "Workspace name."
      },
      "Label": {
        "zh-cn": "工作空间名称",
        "en": "Workspace Name"
      },
      "Value": {
        "Fn::GetAtt": [
          "Workspace",
          "WorkspaceName"
        ]
      }
    },
    "SystemPrometheusId": {
      "Description": {
        "zh-cn": "系统指标Prometheus实例ID。",
        "en": "System metrics Prometheus instance ID."
      },
      "Label": {
        "zh-cn": "系统Prometheus实例ID",
        "en": "System Prometheus ID"
      },
      "Value": {
        "Fn::GetAtt": [
          "SystemPrometheus",
          "PrometheusInstanceId"
        ]
      }
    },
    "AppPrometheusId": {
      "Description": {
        "zh-cn": "应用指标Prometheus实例ID。",
        "en": "App metrics Prometheus instance ID."
      },
      "Label": {
        "zh-cn": "应用Prometheus实例ID",
        "en": "App Prometheus ID"
      },
      "Value": {
        "Fn::GetAtt": [
          "AppPrometheus",
          "PrometheusInstanceId"
        ]
      }
    },
    "TargetPrometheusId": {
      "Description": {
        "zh-cn": "目标Prometheus实例ID。",
        "en": "Target Prometheus instance ID."
      },
      "Label": {
        "zh-cn": "目标Prometheus实例ID",
        "en": "Target Prometheus ID"
      },
      "Value": {
        "Fn::GetAtt": [
          "TargetPrometheus",
          "PrometheusInstanceId"
        ]
      }
    },
    "TargetPrometheusRemoteWriteUrl": {
      "Description": {
        "zh-cn": "目标Prometheus实例Remote Write内网地址。",
        "en": "Target Prometheus instance Remote Write internal URL."
      },
      "Label": {
        "zh-cn": "目标Prometheus Remote Write地址",
        "en": "Target Prometheus Remote Write URL"
      },
      "Value": {
        "Fn::GetAtt": [
          "TargetPrometheus",
          "RemoteWriteIntraUrl"
        ]
      }
    },
    "TargetPrometheusHttpApiUrl": {
      "Description": {
        "zh-cn": "目标Prometheus实例HTTP API内网地址。",
        "en": "Target Prometheus instance HTTP API internal URL."
      },
      "Label": {
        "zh-cn": "目标Prometheus HTTP API地址",
        "en": "Target Prometheus HTTP API URL"
      },
      "Value": {
        "Fn::GetAtt": [
          "TargetPrometheus",
          "HttpApiIntraUrl"
        ]
      }
    },
    "SystemMetricsAggId": {
      "Description": {
        "zh-cn": "系统指标聚合任务组ID。",
        "en": "System metrics aggregation task group ID."
      },
      "Label": {
        "zh-cn": "系统指标聚合任务组ID",
        "en": "System Metrics Agg ID"
      },
      "Value": {
        "Fn::GetAtt": [
          "SystemMetricsAgg",
          "AggTaskGroupId"
        ]
      }
    },
    "AppMetricsAggId": {
      "Description": {
        "zh-cn": "应用指标聚合任务组ID。",
        "en": "App metrics aggregation task group ID."
      },
      "Label": {
        "zh-cn": "应用指标聚合任务组ID",
        "en": "App Metrics Agg ID"
      },
      "Value": {
        "Fn::GetAtt": [
          "AppMetricsAgg",
          "AggTaskGroupId"
        ]
      }
    }
  },
  "Metadata": {
    "ALIYUN::ROS::Interface": {
      "ParameterGroups": [
        {
          "Parameters": [
            "CommonName",
            "StorageDuration",
            "DataRedundancyType"
          ]
        },
        {
          "Parameters": [
            "EnableApm",
            "EnableRum"
          ]
        }
      ]
    }
  }
}