全部产品
Search
文档中心

CloudOps Orchestration Service:ACS-ECS-BulkyInstallARMSAgent

更新时间:Dec 21, 2025

Nama Template

ACS-ECS-BulkyInstallARMSAgent: Melakukan instalasi plug-in ARMS secara batch

Eksekusi Sekarang

Deskripsi Template

Memasang Agen Application Real-Time Monitoring Service (ARMS) pada beberapa instance Elastic Compute Service (ECS) secara bersamaan.

Tipe Template

Otomatis

Pemilik

Alibaba Cloud

Parameter Input

Parameter

Deskripsi

Tipe

Diperlukan

Nilai Default

Batasan

appName

Nama aplikasi yang akan dipantau.

String

Ya

licenseKey

Kunci lisensi yang diperlukan untuk menggunakan fitur pemantauan aplikasi.

String

Ya

targets

Instans target

Json

Ya

regionId

ID wilayah.

String

Tidak

{{ ACS::RegionId }}

action

Jenis Operasi

String

Tidak

install

rateControl

Laju konkurensi eksekusi tugas

Json

Tidak

{'Mode': 'Concurrency', 'MaxErrors': 0, 'Concurrency': 10}

OOSAssumeRole

Peran Resource Access Management (RAM) yang diasumsikan oleh CloudOps Orchestration Service (OOS).

String

Tidak

""

Parameter Output

Parameter

Deskripsi

Tipe

commandOutput

String

Kebijakan Izin yang Diperlukan untuk Menjalankan Template

{
    "Version": "1",
    "Statement": [
        {
            "Action": [
                "ecs:DescribeInstances",
                "ecs:DescribeInvocationResults",
                "ecs:DescribeInvocations",
                "ecs:RunCommand"
            ],
            "Resource": "*",
            "Effect": "Allow"
        },
        {
            "Action": [
                "oos:GetApplicationGroup"
            ],
            "Resource": "*",
            "Effect": "Allow"
        }
    ]
}

Detail

Untuk informasi lebih lanjut, lihat ACS-ECS-BulkyInstallARMSAgent.yml di GitHub.

Konten Template

FormatVersion: OOS-2019-06-01
Description:
  en: Use this template to install ARMS agent on ecs
  zh-cn: Use this template to install the ARMS agent on multiple ECS instances.
  name-en: ACS-ECS-BulkyInstallARMSAgent
  name-zh-cn: Batch Install ARMS Agent
  categories:
    - run_command
Parameters:
  regionId:
    Type: String
    Label:
      en: RegionId
      zh-cn: Region ID
    AssociationProperty: RegionId
    Default: '{{ ACS::RegionId }}'
  action:
    Type: String
    Label:
      en: Action
      zh-cn: Operation Type
    AllowedValues:
      - install
      - upgrade
      - uninstall
    Default: install
  appName:
    Type: String
    Label:
      en: AppName
      zh-cn: Application Name to Monitor
  licenseKey:
    Type: String
    Label:
      en: LicenseKey
      zh-cn: License Key for Application Monitoring
  targets:
    Type: Json
    Label:
      en: TargetInstance
      zh-cn: Target Instance
    AssociationProperty: Targets
    AssociationPropertyMetadata:
      ResourceType: 'ALIYUN::ECS::Instance'
      RegionId: regionId
  rateControl:
    Label:
      en: RateControl
      zh-cn: Concurrency Rate for Task Execution
    Type: Json
    AssociationProperty: RateControl
    Default:
      Mode: Concurrency
      MaxErrors: 0
      Concurrency: 10
  OOSAssumeRole:
    Label:
      en: OOSAssumeRole
      zh-cn: RAM Role Assumed by OOS
    Type: String
    Default: ''
RamRole: '{{ OOSAssumeRole }}'
Tasks:
  - Name: getInstance
    Description:
      en: Views the ECS instances
      zh-cn: Get ECS Instances
    Action: 'ACS::SelectTargets'
    Properties:
      ResourceType: 'ALIYUN::ECS::Instance'
      RegionId: '{{ regionId }}'
      Filters:
        - '{{ targets }}'
    Outputs:
      instanceIds:
        Type: List
        ValueSelector: 'Instances.Instance[].InstanceId'
      instanceInfos:
        Type: List
        ValueSelector: '.Instances.Instance[] | {"osType":.OSType, "instanceId":.InstanceId}'
  - Name: runCommand
    Action: 'ACS::ECS::RunCommand'
    When:
      'Fn::Equals':
        - 'Fn::Jq':
            - First
            - '.|map(select(.instanceId == "{{ ACS::TaskLoopItem }}").osType)[]'
            - '{{ getInstance.instanceInfos }}'
        - linux
    Description:
      en: Execute cloud assistant command
      zh-cn: Execute Cloud Assistant Command
    Properties:
      commandContent: |-
        #!/usr/bin/env bash
        regionId="{{ regionId }}"
        region=`echo $regionId|awk -F "-" '{print $2}'`
        action="{{action}}"
        licenseKey="{{licenseKey}}"
        agentBaseDir="$HOME/.arms"
        pidFileName="supervisor.pid"
        pidFile="${agentBaseDir}/${pidFileName}"
        appName="{{appName}}"
        if [[ "$regionId" =~ "cn-"  ]];then
          DOWNLOAD_URL="http://arms-apm-${region}.oss-${regionId}.aliyuncs.com/"
        elif [[ "$regionId" =~ "ap-southeast-1"  ]];then
          DOWNLOAD_URL="http://arms-apm-ap-southeast.oss-ap-southeast-1-internal.aliyuncs.com/cloud_ap-southeast-1/"
        elif [[ "$regionId" =~ "ap-northeast-1"  ]];then
          DOWNLOAD_URL="http://arms-apm-japan.oss-ap-northeast-1-internal.aliyuncs.com/"
        elif [[ "$regionId" =~ "us-west-1"  ]];then
          DOWNLOAD_URL="http://arms-apm-usw.oss-us-west-1-internal.aliyuncs.com/"
        else
          echo "Current ${regionId} is not supported."
          exit 1
        fi

        function operateJavaAgent() {
        appEnv="java"
        function installAgent() {
          wget -O- "${DOWNLOAD_URL}/install.sh" -q|sh
          currentProcess=`ps -ef |grep java|grep -v "grep --color" `
          if echo $currentProcess|grep "$appName" >/dev/null 2>&1; then
              processIndex=`echo null |${agentBaseDir}/supervisor/cli.sh "$licenseKey" $appName |grep "$appName"  |awk -F ' ' '{print $1}'`
              (echo $processIndex |${agentBaseDir}/supervisor/cli.sh "$licenseKey" $appName )  && echo "Automatically input application index $processIndex for attach $appName."
          else
            echo "It seems that no running $appName application."
          fi
        }

        function uninstallAgent() {
        if [ -f $pidFile ];
        then
            kill -9 `cat $pidFile` > /dev/null 2>&1
            echo "Finished to stop $pidFile."
        fi
        rm -rf $agentBaseDir
        }
        if [ $action = "install" ]; then
            if [ -d ${agentBaseDir}/agent ];
            then
                  uninstallAgent || exit 1
                  installAgent || exit 1
                  echo "Finished to install $appEnv arms agent."
            else
              installAgent || exit 1
              echo "Finished to install $appEnv arms agent."
            fi
        elif [ $action = "upgrade" ]; then
          installAgent || exit 1
          echo "Finished to upgrade $appEnv arms agent."
        else
          uninstallAgent || exit 1
          echo "Finished to uninstall $appEnv arms agent."
        fi
        }
        operateJavaAgent

      instanceId: '{{ ACS::TaskLoopItem }}'
      regionId: '{{ regionId }}'
      commandType: RunShellScript
    Loop:
      Items: '{{ getInstance.instanceIds }}'
      RateControl: '{{ rateControl }}'
      Outputs:
        commandOutputs:
          AggregateType: 'Fn::ListJoin'
          AggregateField: commandOutput
    Outputs:
      commandOutput:
        Type: String
        ValueSelector: invocationOutput
Outputs:
  commandOutput:
    Type: String
    Value: '{{ runCommand.commandOutputs }}'
Metadata:
  ALIYUN::OOS::Interface:
    ParameterGroups:
      - Parameters:
          - action
          - appName
          - licenseKey
        Label:
          default:
            zh-cn: Configure Parameters
            en: Configure Parameters
      - Parameters:
          - regionId
          - targets
        Label:
          default:
            zh-cn: Select Instances
            en: Select Ecs Instances
      - Parameters:
          - rateControl
          - OOSAssumeRole
        Label:
          default:
            zh-cn: Advanced Options
            en: Control Options