The ACS::AlarmTrigger action monitors a CloudMonitor metric and triggers subsequent tasks in an OOS template when the metric crosses a threshold. Use it to build self-healing workflows -- for example, automatically rebooting an ECS instance when its CPU usage exceeds 90%.
How it works
-
An OOS execution containing
ACS::AlarmTriggerstarts in Pending status. -
When the specified metric reaches the threshold, the execution transitions to Active status.
-
OOS runs the subsequent tasks defined in the template to remediate the alert.
AlarmTrigger supports two types of CloudMonitor metrics:
-
ECS native metrics -- available without additional setup.
-
Agent-collected metrics -- require the CloudMonitor agent on the instance. To install the agent, open the CloudMonitor console, go to Host Monitoring, select the target instance, and click Install. See the CloudMonitor metric descriptions to determine which type a metric belongs to.
Limitations
-
A template can contain only one trigger action.
-
The trigger action must be the first task in the template.
-
Trigger actions cannot be used in child templates (embedded templates).
Properties
| Property | Required | Type | Description |
|---|---|---|---|
| Namespace | Yes | String | CloudMonitor namespace of the service to monitor (for example, acs_ecs_dashboard for ECS). Query valid values with the DescribeMetricMetaList operation. |
| MetricName | Yes | String | Metric name (for example, cpu_total). Query valid values with DescribeMetricMetaList. |
| Statistics | Yes | String | Aggregation method applied to the metric data, such as Average, Maximum, or Minimum. Query valid values with DescribeMetricMetaList. |
| ComparisonOperator | Yes | String | Operator that compares the metric value against the threshold. See Comparison operators. |
| Threshold | Yes | String | Value that triggers the alert (for example, "90" for 90% CPU usage). |
| Resources | Yes | String | JSON array specifying the resources to monitor. See Resource formats. |
| Times | Yes | Integer | Number of consecutive breaches required before the alert fires. |
| Interval | No | Integer | Evaluation interval in seconds. Default: 60. |
| SilenceTime | No | Integer | Mute duration in seconds. During this period, only one alert notification is sent even if the metric continuously exceeds the threshold. Default: 86400 (24 hours). Minimum: 3600 (1 hour). |
| Period | No | Integer | Aggregation period in seconds. Default: the metric's original reporting period (typically 60 for ECS metrics). |
| Tags | No | JSON | Filter monitored resources by tag. Format: [{"Key": "k1", "Value": "v1"}]. Mutually exclusive with ResourceGroup. |
| ResourceGroup | No | String | Filter monitored resources by resource group ID (for example, rg-xxxx). Mutually exclusive with Tags. |
Comparison operators
| Value | Meaning |
|---|---|
GreaterThanOrEqualToThreshold |
>= threshold |
GreaterThanThreshold |
> threshold |
LessThanOrEqualToThreshold |
<= threshold |
LessThanThreshold |
< threshold |
NotEqualToThreshold |
!= threshold |
GreaterThanYesterday |
Increase from the same time yesterday |
LessThanYesterday |
Decrease from the same time yesterday |
GreaterThanLastWeek |
Increase from the same time last week |
LessThanLastWeek |
Decrease from the same time last week |
GreaterThanLastPeriod |
Increase from the previous period |
LessThanLastPeriod |
Decrease from the previous period |
Resource formats
| Scope | Format |
|---|---|
| All resources under the current account | [{"resource":"_ALL"}] |
| A specific instance | [{"instanceId":"i-bp123467zxcvb"}] |
| A specific disk partition | [{"instanceId":"i-bp123467zxcvb","device":"/dev/vda1"}] |
| Multiple disk partitions | [{"instanceId":"i-bp123467zxcvb","device":"/dev/vda1"},{"instanceId":"i-bp123467zxcvb","device":"/dev/vdb1"}] |
Outputs
Use the Outputs block to extract values from the alert event JSON. Specify a ValueSelector using a JSON path expression (for example, .instanceId).
Alert event JSON structure:
{
"curLevel": "INFO",
"Minimum": "34.00",
"Maximum": "95.00",
"instanceId": "i-abc12345zxcv",
"Average": "85.00",
"ruleName": "alarmtrigger-13012345678-exec-2130c0c073fa487098d3",
"userId": "13012345678",
"timestamp": "1598349720000",
"executionId": "exec-2130c0c073fa487098d3",
"sourceAliUid": "13012345678"
}
| Field | Description |
|---|---|
| instanceId | ID of the instance that triggered the alert |
| curLevel | Alert severity level |
| Average / Minimum / Maximum | Aggregated metric values |
| ruleName | Name of the alert rule |
| userId | Alibaba Cloud account ID |
| timestamp | Unix timestamp (milliseconds) of the alert event |
| executionId | OOS execution ID |
Syntax
YAML
Tasks:
- Name: <task-name>
Action: 'ACS::AlarmTrigger'
Properties:
Namespace: 'acs_ecs_dashboard'
MetricName: 'cpu_total'
Statistics: 'Average'
ComparisonOperator: 'GreaterThanThreshold'
Threshold: '90'
Resources: '[{"resource":"_ALL"}]'
Times: 1
Interval: 60
SilenceTime: 3600
Outputs:
instanceId:
Type: String
ValueSelector: .instanceId
JSON
{
"Tasks": [
{
"Name": "<task-name>",
"Action": "ACS::AlarmTrigger",
"Properties": {
"Namespace": "acs_ecs_dashboard",
"MetricName": "cpu_total",
"Statistics": "Average",
"ComparisonOperator": "GreaterThanThreshold",
"Threshold": "90",
"Resources": "[{\"resource\":\"_ALL\"}]",
"Times": 1,
"Interval": 60,
"SilenceTime": 3600
},
"Outputs": {
"instanceId": {
"Type": "String",
"ValueSelector": ".instanceId"
}
}
}
]
}
Example: Reboot an ECS instance on high CPU
This template monitors ECS instances matching specific tags. When an instance's average CPU usage exceeds the threshold in a 1-minute evaluation window, OOS verifies the instance has the expected tag, then reboots it.
Prerequisites:
-
The CloudMonitor agent is installed on the target instances
-
The
OOSServiceRoleRAM role exists (or specify a custom role)
YAML
FormatVersion: OOS-2019-06-01
Description:
en: Reboot ECS instance with specified tag when its CPU utilization exceeded threshold. The selected instance must already have the Cloud Monitor agent installed.
name-en: ACS-ECS-RebootInstanceAtHighCpuByTags
categories:
- alarm-trigger
Parameters:
tags:
Type: Json
Description:
en: The tags to select ECS instances.
AssociationProperty: Tags
threshold:
Type: Number
Description:
en: The CPU utilization threshold.
silenceTime:
Type: Number
Description:
en: The silence time of alarm (seconds).
Default: 60
OOSAssumeRole:
Description:
en: The RAM role to be assumed by OOS.
Type: String
Default: OOSServiceRole
RamRole: '{{ OOSAssumeRole }}'
Tasks:
- Name: alarmTrigger
Action: 'ACS::AlarmTrigger'
Description:
en: Set the CPU utilization alarm for ECS instance.
Properties:
Namespace: acs_ecs_dashboard
MetricName: cpu_total
Statistics: Average
ComparisonOperator: GreaterThanThreshold
Threshold: '{{threshold}}'
Times: 1
SilenceTime: '{{ silenceTime }}'
Period: 60
Interval: 60
Outputs:
InstanceId:
Type: String
ValueSelector: .instanceId
- Name: CheckForInstances
Action: 'ACS::CheckFor'
Description:
en: Check ECS instance has specified tag.
OnError: 'ACS::END'
Properties:
Service: ECS
API: DescribeInstances
Parameters:
Tags: '{{ tags }}'
InstanceIds: '["{{ alarmTrigger.instanceId }}"]'
PropertySelector: TotalCount
DesiredValues:
- 1
- Name: RebootInstance
Action: 'ACS::ECS::RebootInstance'
Description:
en: Restarts the ECS instances.
Properties:
instanceId: '{{ alarmTrigger.instanceId }}'
JSON
{
"FormatVersion": "OOS-2019-06-01",
"Description": {
"en": "Reboot ECS instance with specified tag when its CPU utilization exceeded threshold. The selected instance must already have the Cloud Monitor agent installed.",
"name-en": "ACS-ECS-RebootInstanceAtHighCpuByTags",
"categories": ["alarm-trigger"]
},
"Parameters": {
"tags": {
"Type": "Json",
"Description": { "en": "The tags to select ECS instances." },
"AssociationProperty": "Tags"
},
"threshold": {
"Type": "Number",
"Description": { "en": "The CPU utilization threshold." }
},
"silenceTime": {
"Type": "Number",
"Description": { "en": "The silence time of alarm (seconds)." },
"Default": 60
},
"OOSAssumeRole": {
"Description": { "en": "The RAM role to be assumed by OOS." },
"Type": "String",
"Default": "OOSServiceRole"
}
},
"RamRole": "{{ OOSAssumeRole }}",
"Tasks": [
{
"Name": "alarmTrigger",
"Action": "ACS::AlarmTrigger",
"Description": { "en": "Set the CPU utilization alarm for ECS instance." },
"Properties": {
"Namespace": "acs_ecs_dashboard",
"MetricName": "cpu_total",
"Statistics": "Average",
"ComparisonOperator": "GreaterThanThreshold",
"Threshold": "{{threshold}}",
"Times": 1,
"SilenceTime": "{{ silenceTime }}",
"Period": 60,
"Interval": 60
},
"Outputs": {
"InstanceId": {
"Type": "String",
"ValueSelector": ".instanceId"
}
}
},
{
"Name": "CheckForInstances",
"Action": "ACS::CheckFor",
"Description": { "en": "Check ECS instance has specified tag." },
"OnError": "ACS::END",
"Properties": {
"Service": "ECS",
"API": "DescribeInstances",
"Parameters": {
"Tags": "{{ tags }}",
"InstanceIds": "[\"{{ alarmTrigger.instanceId }}\"]"
},
"PropertySelector": "TotalCount",
"DesiredValues": [1]
}
},
{
"Name": "RebootInstance",
"Action": "ACS::ECS::RebootInstance",
"Description": { "en": "Restarts the ECS instances." },
"Properties": {
"instanceId": "{{ alarmTrigger.instanceId }}"
}
}
]
}