Template name
ACS-ECS-BulkyInstallARMSAgent
Template description
Installs the Application Real-Time Monitoring Service (ARMS) agent on multiple Elastic Compute Service (ECS) instances at a time.
Template type
Automated
Owner
Alibaba Cloud
Input parameters
Parameter | Description | Type | Required | Default value | Limit |
appName | The name of the application to be monitored. | String | Yes | ||
licenseKey | The license key that is required to use the application monitoring feature. | String | Yes | ||
targets | The ECS instances on which you want to install the ARMS agent. | Json | Yes | ||
regionId | The region ID. | String | No | {{ ACS::RegionId }} | |
action | The operation that you want to perform. | String | No | install | |
rateControl | The rate control settings. | Json | No | {'Mode': 'Concurrency', 'MaxErrors': 0, 'Concurrency': 10} | |
OOSAssumeRole | The Resource Access Management (RAM) role that is assumed by CloudOps Orchestration Service (OOS). | String | No | "" |
Output parameters
Parameter | Description | Type |
commandOutput | String |
Permission policy that is required to execute the template
{
"Version": "1",
"Statement": [
{
"Action": [
"ecs:DescribeInstances",
"ecs:DescribeInvocationResults",
"ecs:DescribeInvocations",
"ecs:RunCommand"
],
"Resource": "*",
"Effect": "Allow"
}
]
}
References
For more information, see ACS-ECS-BulkyInstallARMSAgent.yml at GitHub.
Template content
FormatVersion: OOS-2019-06-01
Description:
en: Use this template to install ARMS agent on ecs
zh-cn: the description in Chinese
name-en: ACS-ECS-BulkyInstallARMSAgent
name-zh-cn: the description in Chinese
categories:
- run_command
Parameters:
regionId:
Type: String
Label:
en: RegionId
zh-cn: the description in Chinese
AssociationProperty: RegionId
Default: '{{ ACS::RegionId }}'
action:
Type: String
Label:
en: Action
zh-cn: the description in Chinese
AllowedValues:
- install
- upgrade
- uninstall
Default: install
appName:
Type: String
Label:
en: AppName
zh-cn: the description in Chinese
licenseKey:
Type: String
Label:
en: LicenseKey
zh-cn: the description in Chinese
targets:
Type: Json
Label:
en: TargetInstance
zh-cn: the description in Chinese
AssociationProperty: Targets
AssociationPropertyMetadata:
ResourceType: 'ALIYUN::ECS::Instance'
RegionId: regionId
rateControl:
Label:
en: RateControl
zh-cn: the description in Chinese
Type: Json
AssociationProperty: RateControl
Default:
Mode: Concurrency
MaxErrors: 0
Concurrency: 10
OOSAssumeRole:
Label:
en: OOSAssumeRole
zh-cn: the description in Chinese
Type: String
Default: ''
RamRole: '{{ OOSAssumeRole }}'
Tasks:
- Name: getInstance
Description:
en: Views the ECS instances
zh-cn: the description in Chinese
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: the description in Chinese
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: the description in Chinese
en: Configure Parameters
- Parameters:
- regionId
- targets
Label:
default:
zh-cn: the description in Chinese
en: Select Ecs Instances
- Parameters:
- rateControl
- OOSAssumeRole
Label:
default:
zh-cn: the description in Chinese
en: Control Options