Template name
ACS-ECS-AlarmAccountResourceUsage
Template description
Monitors the resource usage within your Alibaba Cloud account and sends alert notifications if the resource usage exceeds the specified threshold.
Template type
Automated
Owner
Alibaba Cloud
Input parameters
Parameter | Description | Type | Required | Default value | Limit |
webHookUrl | The webhook URL to which alert notifications are sent. | String | Yes | ||
regionId | The region ID. | String | No | {{ ACS::RegionId }} | |
threshold | The resource usage threshold based on which alerts are triggered. | Number | No | 80 | |
OOSAssumeRole | The Resource Access Management (RAM) role that is assumed by CloudOps Orchestration Service (OOS). | String | No | OOSServiceRole |
Output parameters
None
Permission policy that is required to execute the template
{
"Version": "1",
"Statement": [
{
"Action": [
"ecs:DescribeAccountAttributes"
],
"Resource": "*",
"Effect": "Allow"
}
]
}
References
For more information, see ACS-ECS-AlarmAccountResourceUsage.yml at GitHub.
Template content
FormatVersion: OOS-2019-06-01
Description:
en: Resource usage exceeds threshold alarm notification
zh-cn: the description in Chinese
name-en: ACS-ECS-AlarmAccountResourceUsage
name-zh-cn: the description in Chinese
Parameters:
regionId:
Type: String
Label:
en: RegionId
zh-cn: the description in Chinese
AssociationProperty: RegionId
Default: '{{ ACS::RegionId }}'
threshold:
Label:
en: Threshold
zh-cn: the description in Chinese
Description:
en: example:10 is 10%,50 is 50%
zh-cn: the description in Chinese
Type: Number
Default: 80
MinValue: 20
MaxValue: 99
webHookUrl:
Description:
en: 'e.g.https://oapi.dingtalk.com/robot/send?access_token=1234zxcvaksdq31414,acquiring DingTalk webhook please refer to second appendix in https://help.aliyun.com/document_detail/144679.html.'
zh-cn: the description in Chinese '
Label:
en: WebHookUrl
zh-cn: the description in Chinese
Type: String
OOSAssumeRole:
Label:
en: OOSAssumeRole
zh-cn: the description in Chinese
Type: String
Default: OOSServiceRole
RamRole: '{{ OOSAssumeRole }}'
Tasks:
- Name: timerTrigger
Action: 'ACS::TimerTrigger'
Description:
en: Triggers a task as scheduled by specifying Cron expression
zh-cn: the description in Chinese
Properties:
Type: rate
Expression: 30 minutes
EndDate: '2099-12-01T00:00:00Z'
- Name: getAccountAttributes
Action: 'ACS::ExecuteApi'
Description:
en: Query the quotas of ECS resources that you can create in a region
zh-cn: the description in Chinese
Properties:
Service: ECS
API: DescribeAccountAttributes
Parameters:
RegionId: '{{ regionId }}'
Outputs:
usedPostpaidInstanceVcpuCount:
ValueSelector: '.AccountAttributeItems.AccountAttributeItem[13].AttributeValues.ValueItem[].Value | tonumber'
Type: Number
usedSpotInstanceVcpuCount:
ValueSelector: '.AccountAttributeItems.AccountAttributeItem[14].AttributeValues.ValueItem[].Value | tonumber'
Type: Number
usedPostpaidYundiskCapacityCloudEfficiency:
ValueSelector: '.AccountAttributeItems.AccountAttributeItem[16].AttributeValues.ValueItem[0].Value | tonumber'
Type: Number
usedPostpaidYundiskCapacityCloudSsd:
ValueSelector: '.AccountAttributeItems.AccountAttributeItem[16].AttributeValues.ValueItem[1].Value | tonumber'
Type: Number
usedPostpaidYundiskCapacityCloudEssd:
ValueSelector: '.AccountAttributeItems.AccountAttributeItem[16].AttributeValues.ValueItem[2].Value | tonumber'
Type: Number
maxPostpaidInstanceVcpuCount:
ValueSelector: '.AccountAttributeItems.AccountAttributeItem[6].AttributeValues.ValueItem[].Value | tonumber'
Type: Number
maxSpotInstanceVcpuCount:
ValueSelector: '.AccountAttributeItems.AccountAttributeItem[7].AttributeValues.ValueItem[].Value | tonumber'
Type: Number
maxPostpaidYundiskCapacityCloudEfficiency:
ValueSelector: '.AccountAttributeItems.AccountAttributeItem[15].AttributeValues.ValueItem[0].Value | tonumber'
Type: Number
maxPostpaidYundiskCapacityCloudSsd:
ValueSelector: '.AccountAttributeItems.AccountAttributeItem[15].AttributeValues.ValueItem[1].Value | tonumber'
Type: Number
maxPostpaidYundiskCapacityCloudEssd:
ValueSelector: '.AccountAttributeItems.AccountAttributeItem[15].AttributeValues.ValueItem[2].Value | tonumber'
Type: Number
- Name: checkResourceUsage
Action: 'ACS::Choice'
Description:
en: Choose the notification task by usage
zh-cn: the description in Chinese
Properties:
DefaultTask: 'ACS::END'
Choices:
- When:
'Fn::Equals':
- true
- 'Fn::Jq':
- First
- '({{getAccountAttributes.usedPostpaidInstanceVcpuCount}} / {{getAccountAttributes.maxPostpaidInstanceVcpuCount}}) >= {{ threshold }}/100'
- '{"": ""}'
NextTask: alarmNotify
- When:
'Fn::Equals':
- true
- 'Fn::Jq':
- First
- '({{getAccountAttributes.usedSpotInstanceVcpuCount}} / {{getAccountAttributes.maxSpotInstanceVcpuCount}}) >= {{ threshold }}/100'
- '{"": ""}'
NextTask: alarmNotify
- When:
'Fn::Equals':
- true
- 'Fn::Jq':
- First
- '({{getAccountAttributes.usedPostpaidYundiskCapacityCloudEfficiency}} / {{getAccountAttributes.maxPostpaidYundiskCapacityCloudEfficiency}}) >= {{ threshold }}/100'
- '{"": ""}'
NextTask: alarmNotify
- When:
'Fn::Equals':
- true
- 'Fn::Jq':
- First
- '({{getAccountAttributes.usedPostpaidYundiskCapacityCloudSsd}} / {{getAccountAttributes.maxPostpaidYundiskCapacityCloudSsd}}) >= {{ threshold }}/100'
- '{"": ""}'
NextTask: alarmNotify
- When:
'Fn::Equals':
- true
- 'Fn::Jq':
- First
- '({{getAccountAttributes.usedPostpaidYundiskCapacityCloudEssd}} / {{getAccountAttributes.maxPostpaidYundiskCapacityCloudEssd}}) >= {{ threshold }}/100'
- '{"": ""}'
NextTask: alarmNotify
- Name: alarmNotify
Action: 'ACS::Notify'
OnSuccess: 'ACS::END'
Description:
en: Resource usage exceeds threshold alarm notification
zh-cn: the description in Chinese
Properties:
NotifyType: WebHook
WebHook:
URI: '{{ webHookUrl }}'
Headers:
Content-Type: application/json
Content:
msgtype: text
text:
content:
'Fn::Join':
- '|-|-|'
- - 'Fn::If':
- 'Fn::Equals':
- true
- 'Fn::Jq':
- First
- '({{getAccountAttributes.usedPostpaidInstanceVcpuCount}} / {{getAccountAttributes.maxPostpaidInstanceVcpuCount}}) >= {{ threshold }}/100'
- '{"": ""}'
- '(The PostpaidInstanceVcpuCount usage under your account exceeds {{ threshold }}%. The vCPU usage of the pay-as-you-go instances in your account has exceeded {{threshold}}%. )'
- ''
- 'Fn::If':
- 'Fn::Equals':
- true
- 'Fn::Jq':
- First
- '({{getAccountAttributes.usedSpotInstanceVcpuCount}} / {{getAccountAttributes.maxSpotInstanceVcpuCount}}) >= {{ threshold }}/100'
- '{"": ""}'
- '(The SpotInstanceVcpuCount usage under your account exceeds {{ threshold }}%. The vCPU usage of the preemptible instances in your account has exceeded {{threshold}}%. )'
- ''
- 'Fn::If':
- 'Fn::Equals':
- true
- 'Fn::Jq':
- First
- '({{getAccountAttributes.usedPostpaidYundiskCapacityCloudEfficiency}} / {{getAccountAttributes.maxPostpaidYundiskCapacityCloudEfficiency}}) >= {{ threshold }}/100'
- '{"": ""}'
- '(The PostpaidYundiskCapacityCloudEfficiency usage under your account exceeds {{ threshold }}%. The usage of pay-as-you-go ultra disks that are used as data disks in your account has exceeded {{threshold}}%. )'
- ''
- 'Fn::If':
- 'Fn::Equals':
- true
- 'Fn::Jq':
- First
- '({{getAccountAttributes.usedPostpaidYundiskCapacityCloudSsd}} / {{getAccountAttributes.maxPostpaidYundiskCapacityCloudSsd}}) >= {{ threshold }}/100'
- '{"": ""}'
- '(The PostpaidYundiskCapacityCloudSsd usage under your account exceeds {{ threshold }}%. The usage of pay-as-you-go SSDs that are used as data disks in your account has exceeded {{threshold}}%. )'
- ''
- 'Fn::If':
- 'Fn::Equals':
- true
- 'Fn::Jq':
- First
- '({{getAccountAttributes.usedPostpaidYundiskCapacityCloudEssd}} / {{getAccountAttributes.maxPostpaidYundiskCapacityCloudEssd}}) >= {{ threshold }}/100'
- '{"": ""}'
- '(The PostpaidYundiskCapacityCloudEssd usage under your account exceeds {{ threshold }}%. The usage of pay-as-you-go Enterprise SSDs (ESSDs) that are used as data disks in your account has exceeded {{threshold}}%. )'
- ''
Metadata:
ALIYUN::OOS::Interface:
ParameterGroups:
- Parameters:
- regionId
- threshold
- webHookUrl
Label:
default:
zh-cn: the description in Chinese
en: Configure Parameters
- Parameters:
- OOSAssumeRole
Label:
default:
zh-cn: the description in Chinese
en: Control Options