テンプレート名
ACS-ECS-BulkyInstallARMSAgent:ARMS プラグインをバッチインストールします
テンプレートの説明
複数の Elastic Compute Service (ECS) インスタンスに Application Real-Time Monitoring Service (ARMS) エージェントを一括インストールします。
テンプレートタイプ
自動化
所有者
Alibaba Cloud
入力パラメーター
パラメーター | 説明 | タイプ | 必須 | デフォルト値 | 制限 |
appName | 監視対象のアプリケーション名。 | String | はい | ||
licenseKey | アプリケーション監視機能を使用するために必要なライセンスキー。 | String | はい | ||
targets | ターゲットインスタンス | Json | はい | ||
regionId | リージョン ID。 | String | いいえ | {{ ACS::RegionId }} | |
action | 操作タイプ | String | いいえ | install | |
rateControl | タスク実行の同時実行率 | Json | いいえ | {'Mode': 'Concurrency', 'MaxErrors': 0, 'Concurrency': 10} | |
OOSAssumeRole | CloudOps Orchestration Service (OOS) がアシュームする Resource Access Management (RAM) ロール。 | String | いいえ | "" |
出力パラメーター
パラメーター | 説明 | タイプ |
commandOutput | String |
テンプレートを実行するために必要な権限ポリシー
{
"Version": "1",
"Statement": [
{
"Action": [
"ecs:DescribeInstances",
"ecs:DescribeInvocationResults",
"ecs:DescribeInvocations",
"ecs:RunCommand"
],
"Resource": "*",
"Effect": "Allow"
},
{
"Action": [
"oos:GetApplicationGroup"
],
"Resource": "*",
"Effect": "Allow"
}
]
}
詳細
詳細については、GitHub の ACS-ECS-BulkyInstallARMSAgent.yml をご参照ください。
テンプレートコンテンツ
FormatVersion: OOS-2019-06-01
Description:
ja: このテンプレートを使用して、複数の ECS インスタンスに ARMS エージェントをインストールします。
name-ja: ARMS エージェントの一括インストール
categories:
- run_command
Parameters:
regionId:
Type: String
Label:
ja: リージョン ID
AssociationProperty: RegionId
Default: '{{ ACS::RegionId }}'
action:
Type: String
Label:
ja: 操作タイプ
AllowedValues:
- install
- upgrade
- uninstall
Default: install
appName:
Type: String
Label:
ja: 監視するアプリケーション名
licenseKey:
Type: String
Label:
ja: アプリケーション監視のライセンスキー
targets:
Type: Json
Label:
ja: ターゲットインスタンス
AssociationProperty: Targets
AssociationPropertyMetadata:
ResourceType: 'ALIYUN::ECS::Instance'
RegionId: regionId
rateControl:
Label:
ja: タスク実行の同時実行率
Type: Json
AssociationProperty: RateControl
Default:
Mode: Concurrency
MaxErrors: 0
Concurrency: 10
OOSAssumeRole:
Label:
ja: OOS が引き受ける RAM ロール
Type: String
Default: ''
RamRole: '{{ OOSAssumeRole }}'
Tasks:
- Name: getInstance
Description:
ja: ECS インスタンスを表示します
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:
ja: クラウドアシスタントコマンドを実行します
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 "現在の ${regionId} はサポートされていません。"
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 "${appName} をアタッチするために、アプリケーションインデックス ${processIndex} を自動的に入力しました。"
else
echo "実行中の ${appName} アプリケーションが見つからないようです。"
fi
}
function uninstallAgent() {
if [ -f $pidFile ];
then
kill -9 `cat $pidFile` > /dev/null 2>&1
echo "${pidFile} の停止が完了しました。"
fi
rm -rf $agentBaseDir
}
if [ $action = "install" ]; then
if [ -d ${agentBaseDir}/agent ];
then
uninstallAgent || exit 1
installAgent || exit 1
echo "${appEnv} ARMS エージェントのインストールが完了しました。"
else
installAgent || exit 1
echo "${appEnv} ARMS エージェントのインストールが完了しました。"
fi
elif [ $action = "upgrade" ]; then
installAgent || exit 1
echo "${appEnv} ARMS エージェントのアップグレードが完了しました。"
else
uninstallAgent || exit 1
echo "${appEnv} ARMS エージェントのアンインストールが完了しました。"
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:
ja: パラメーターの設定
- Parameters:
- regionId
- targets
Label:
default:
ja: ECS インスタンスの選択
- Parameters:
- rateControl
- OOSAssumeRole
Label:
default:
ja: 制御オプション