All Products
Search
Document Center

CloudOps Orchestration Service:ACS-ECS-RunCommandWhenDiskUsageLimitExceeded

Last Updated:Nov 22, 2024

Template name

ACS-ECS-RunCommandWhenDiskUsageLimitExceeded

Execute Now

Template description

Runs a command if the usage of a disk on an Elastic Compute Service (ECS) instance exceeds a specific threshold.

Template type

Automated

Owner

Alibaba Cloud

Input parameters

Parameter

Description

Type

Required

Default value

Limit

instanceId

The ECS instance whose disk usage you want to monitor.

String

Yes

threshold

The disk usage threshold.

String

Yes

diskPartition

The name of the disk partition whose usage you want to monitor.

String

Yes

commandType

The language of the O&M script to be run by Cloud Assistant.

String

Yes

commandToRun

The command to be run when the disk usage exceeds the threshold.

String

Yes

tags

The tag of the ECS instance.

Json

No

[]

silenceTime

The silence period during which only one alert notification is sent if the disk usage repeatedly exceeds the threshold. Unit: seconds.

Number

No

300

OOSAssumeRole

The RAM role that is assumed by CloudOps Orchestration Service (OOS).

String

No

""

Output parameters

Parameter

Description

Type

instanceId

String

commandOutput

String

Permission policy that is required to execute the template

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

References

For more information, see ACS-ECS-RunCommandWhenDiskUsageLimitExceeded.yml at GitHub.

Template content

FormatVersion: OOS-2019-06-01
Description:
  en: Run command when disk usage limit is exceeded
  zh-cn: 当某磁盘使用率过高时执行某命令
  name-en: ACS-ECS-RunCommandWhenDiskUsageLimitExceeded
  name-zh-cn: 当某磁盘使用率超过阈值时执行命令
  categories:
    - alarm-trigger
Parameters:
  instanceId:
    Type: String
    Label:
      en: InstanceId
      zh-cn: 将要监控的实例
    AssociationProperty: ALIYUN::ECS::Instance::InstanceId
    AssociationPropertyMetadata:
      RegionId: '{{ ACS::RegionId }}'
  threshold:
    Type: String
    Description:
      en: e.g. 80 means 80%
      zh-cn: 例如80,则意味着80%的磁盘使用率
    Label:
      en: Threshold
      zh-cn: 磁盘使用率阈值
  diskPartition:
    Type: String
    Description:
      en: e.g."/dev/vda1"or"C:\\"
      zh-cn: 如/dev/vda1或者C:\\
    Label:
      en: DiskPartition
      zh-cn: 要监控的磁盘分区名称
  commandType:
    Label:
      en: CommandType
      zh-cn: 云助手执行的运维脚本的语言类型
    Type: String
    AllowedValues:
      - RunShellScript
      - RunBatScript
      - RunPowerShellScript
  tags:
    Type: Json
    Label:
      en: Tags
      zh-cn: 实例的标签
    AssociationProperty: Tags
    Default: []
  commandToRun:
    Type: String
    Label:
      en: CommandToRun
      zh-cn: 当磁盘使用量超过阈值时执行的命令
  silenceTime:
    Type: Number
    Description:
      en: When the monitoring data continues to exceed the alarm rule threshold, only one alarm notification will be sent in each silent period
      zh-cn: 当监控数据持续超过报警规则阈值时,每个沉默周期内只发送1次报警通知
    Label:
      en: CilenceTime
      zh-cn: 告警通道沉默周期(秒)
    Default: 300
  OOSAssumeRole:
    Label:
      en: OOSAssumeRole
      zh-cn: OOS扮演的RAM角色
    Type: String
    Default: ''
RamRole: '{{ OOSAssumeRole }}'
Tasks:
  - Name: alarmTrigger
    Action: 'ACS::AlarmTrigger'
    Description:
      en: Set the diskusage_utilization alarm for specified disk partition
      zh-cn: 设置对某磁盘分区的使用率进行监控
    Properties:
        Namespace: 'acs_ecs_dashboard'
        MetricName: 'diskusage_utilization'
        Statistics: 'Maximum'
        ComparisonOperator: 'GreaterThanThreshold'
        Threshold: '{{threshold}}'
        Resources: '[{"instanceId":"{{ instanceId }}","device":"{{ diskPartition }}"}]'
        Times: 1
        SilenceTime: '{{silenceTime}}'
        Tags: '{{ tags }}'
    Outputs:
      instanceId:
        Type: String
        ValueSelector: .instanceId
  - Name: runCommand
    Action: ACS::ECS::RunCommand
    Description:
      en: Run cloud assistant command on ECS instance
      zh-cn: 在实例中运行云助手命令
    Properties:
      commandContent: '{{ commandToRun }}'
      commandType: '{{ commandType }}'
      instanceId: '{{ instanceId }}'
    Outputs:
      commandOutput:
        Type: String
        ValueSelector: invocationOutput
Outputs:
  instanceId:
    Value: '{{ alarmTrigger.instanceId }}'
    Type: String
  commandOutput:
    Type: String
    Value: '{{ runCommand.commandOutput }}'
Metadata:
  ALIYUN::OOS::Interface:
    ParameterGroups:
      - Parameters:
          - instanceId
        Label:
          default:
            zh-cn: 实例选择
            en: Select ECS Instance
      - Parameters:
          - threshold
          - diskPartition
          - silenceTime
          - tags
        Label:
          default:
            zh-cn: 告警配置
            en: Alarm Configure
      - Parameters:
          - commandType
          - commandToRun
        Label:
          default:
            zh-cn: 执行命令选型
            en: Run Command Options
      - Parameters:
          - OOSAssumeRole
        Label:
          default:
            zh-cn: 高级选项
            en: Control Options