Template name
Sends an alert notification when the price or discount of spot instances in a scaling group exceeds a specified threshold.
Template description
Monitors the price and discount of spot instances in a scaling group and sends an alert notification when the value exceeds a specified threshold.
Template type
Automation
Owner
Alibaba Cloud
Input parameters
|
Parameter name |
Description |
Type |
Required |
Default value |
Constraints |
|
scalingGroupId |
The ID of the scaling group. |
List |
Yes |
||
|
threshold |
The price or discount threshold. |
Number |
Yes |
||
|
webhook |
The DingTalk webhook URL for receiving alert messages. |
String |
Yes |
||
|
region |
The region ID. |
String |
No |
{{ ACS::RegionId }} |
|
|
taskType |
The type of the monitoring job. |
String |
No |
Discount |
|
|
rateControl |
The concurrency rate for task execution. |
Json |
No |
{'Mode': 'Concurrency', 'MaxErrors': 100, 'Concurrency': 10} |
|
|
OOSAssumeRole |
The RAM role that OOS assumes. |
String |
No |
OOSServiceRole |
Output parameters
|
Parameter name |
Description |
Type |
|
allThresholdInfo |
List |
Required access policy for execution
{
"Version": "1",
"Statement": [
{
"Action": [
"ess:DescribeScalingConfigurations",
"ess:DescribeScalingGroups"
],
"Resource": "*",
"Effect": "Allow"
},
{
"Action": [
"ecs:DescribeSpotPriceHistory",
"ecs:DescribeVSwitches"
],
"Resource": "*",
"Effect": "Allow"
}
]
}
Details
ACS-ECS-AlarmWhenDiscountOrSpotPriceExceedsThresholdByScalingGroup details
Template content
FormatVersion: OOS-2019-06-01
Description:
en: Monitors the price and discount of spot instances in a scaling group and sends an alert notification if the value exceeds a specified threshold.
zh-cn: Monitors the price and discount of spot instances in a scaling group and sends an alert notification if the value exceeds a specified threshold.
name-en: ACS-ECS-AlarmWhenDiscountOrSpotPriceExceedsThresholdByScalingGroup
name-zh-cn: Sends an alert when the price or discount of spot instances in a scaling group exceeds a threshold.
Parameters:
region:
Type: String
Label:
en: Region ID
zh-cn: Region ID
Description:
en: The region.
zh-cn: The region.
AssociationProperty: RegionId
Default: '{{ ACS::RegionId }}'
scalingGroupId:
Description:
en: The ID of the Auto Scaling group.
zh-cn: The ID of the Auto Scaling group.
Label:
en: Scaling Group ID
zh-cn: Scaling Group ID
Type: List
taskType:
Description:
en: The type of the monitoring job. Valid values are Discount (monitors discount) and Price (monitors price).
zh-cn: The type of the monitoring job. Valid values are Discount (monitors discount) and Price (monitors price).
Label:
en: Monitoring Job Type
zh-cn: Monitoring Job Type
Type: String
Default: Discount
AllowedValues:
- Discount
- Price
threshold:
Description:
en: The price or discount threshold. For example, if you monitor discounts, a value of 10 means 10% of the pay-as-you-go price (a 90% discount), and 50 means 50% of the pay-as-you-go price. You can also enter a direct price value for the threshold.
zh-cn: The price or discount threshold. For example, if you monitor discounts, a value of 10 means 10% of the pay-as-you-go price (a 90% discount), and 50 means 50% of the pay-as-you-go price. You can also enter a direct price value for the threshold.
Label:
en: Price/Discount Threshold
zh-cn: Price/Discount Threshold
Type: Number
webhook:
Label:
en: DingTalk Webhook URL
zh-cn: DingTalk Webhook URL
Description:
en: 'Example: https://oapi.dingtalk.com/robot/send?access_token=bac51db2e39418ec6c2dbb27fd111bc7xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
zh-cn: 'Example: https://oapi.dingtalk.com/robot/send?access_token=bac51db2e39418ec6c2dbb27fd111bc7xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
Type: String
rateControl:
Label:
en: Task Execution Concurrency
zh-cn: Task Execution Concurrency
Type: Json
AssociationProperty: RateControl
Default:
Mode: Concurrency
MaxErrors: 100
Concurrency: 10
OOSAssumeRole:
Label:
en: RAM Role for OOS to Assume
zh-cn: RAM Role for OOS to Assume
Type: String
Default: OOSServiceRole
RamRole: '{{ OOSAssumeRole }}'
Tasks:
- Name: describeScalingGroups
Action: 'ACS::ExecuteAPI'
Description:
en: Queries Auto Scaling groups.
zh-cn: Queries Auto Scaling groups.
Properties:
Service: ESS
API: DescribeScalingGroups
Parameters:
RegionId: '{{ region }}'
ScalingGroupId1: '{{ ACS::TaskLoopItem }}'
Outputs:
scalingGroupInfo:
Type: Json
ValueSelector: '.ScalingGroups.ScalingGroup[] | {"scalingConfigurationId":.ActiveScalingConfigurationId, "scalingGroupId":.ScalingGroupId, "vSwitchIds": .VSwitchIds.VSwitchId}'
Loop:
Items: '{{ scalingGroupId }}'
RateControl: '{{ rateControl }}'
Outputs:
scalingGroupInfos:
AggregateType: 'Fn::ListJoin'
AggregateField: scalingGroupInfo
- Name: describeScalingConfigurations
Action: 'ACS::ExecuteAPI'
Description:
en: Queries existing scaling configurations.
zh-cn: Queries existing scaling configurations.
Properties:
Service: ESS
API: DescribeScalingConfigurations
Parameters:
RegionId: '{{ region }}'
ScalingConfigurationId1:
'Fn::Jq':
- First
- .scalingConfigurationId
- '{{ ACS::TaskLoopItem }}'
Outputs:
scalingConfigurationInfo:
Type: Json
ValueSelector: '.ScalingConfigurations.ScalingConfiguration[] | {"instanceTypes":.InstanceTypes.InstanceType, "scalingConfigurationId":.ScalingConfigurationId}'
Loop:
Items: '{{ describeScalingGroups.scalingGroupInfos }}'
RateControl: '{{ rateControl }}'
Outputs:
scalingConfigurationInfos:
AggregateType: 'Fn::ListJoin'
AggregateField: scalingConfigurationInfo
- Name: describeVSwitches
Action: 'ACS::ExecuteAPI'
Description:
en: Queries existing vSwitches.
zh-cn: Queries existing vSwitches.
Properties:
Service: ECS
API: DescribeVSwitches
Parameters:
RegionId: '{{ region }}'
VSwitchId: '{{ ACS::TaskLoopItem }}'
Outputs:
zoneInfo:
Type: Json
ValueSelector: '.VSwitches.VSwitch[] | {"vSwitchId":.VSwitchId, "zoneId":.ZoneId}'
Loop:
Items:
'Fn::MergeList':
'Fn::Jq':
- All
- '.[].vSwitchIds'
- '{{ describeScalingGroups.scalingGroupInfos }}'
RateControl: '{{ rateControl }}'
Outputs:
zoneInfos:
AggregateType: 'Fn::ListJoin'
AggregateField: zoneInfo
- Name: wetherOutPutPriceInfo
Action: 'ACS::Choice'
Description:
en: Checks whether to query prices.
zh-cn: Checks whether to query prices.
Properties:
DefaultTask: instanceThresholdInfo
Choices:
- When:
'Fn::Equals':
- []
- 'Fn::MergeList': '{{ describeScalingGroups.scalingGroupInfos }}'
NextTask: 'ACS::END'
- Name: instanceThresholdInfo
Action: 'ACS::ECS::AlarmSpotPriceOrDiscountThresholdByScalingGroup'
Description:
en: Monitors the discount or price for the Auto Scaling group.
zh-cn: Monitors the discount or price for the Auto Scaling group.
Properties:
regionId: '{{region}}'
threshold: '{{ threshold }}'
taskType: '{{ taskType }}'
vSwitchId:
'Fn::Jq':
- First
- .vSwitchId
- '{{ ACS::TaskLoopItem }}'
scalingConfigurationId:
'Fn::Jq':
- First
- .scalingConfigurationId
- '{{ ACS::TaskLoopItem }}'
configurationInfos: '{{ describeScalingConfigurations.scalingConfigurationInfos }}'
scalingGroupId:
'Fn::Jq':
- First
- .scalingGroupId
- '{{ ACS::TaskLoopItem }}'
zoneIds: '{{ describeVSwitches.zoneInfos }}'
Outputs:
thresholdInfo:
Type: List
ValueSelector: instanceThresholdInfos
Loop:
Items:
'Fn::Jq':
- All
- '.[] | {scalingConfigurationId, scalingGroupId, "vSwitchId":.vSwitchIds[]}'
- 'Fn::MergeList':
'Fn::Jq':
- First
- '. | map(. as $item | [$item])'
- '{{ describeScalingGroups.scalingGroupInfos }}'
RateControl: '{{ rateControl }}'
Outputs:
thresholdInfos:
AggregateField: thresholdInfo
AggregateType: 'Fn::ListJoin'
- Name: wetherNodifyWebhook
Action: 'ACS::Choice'
Description:
en: Checks whether to send an alert notification.
zh-cn: Checks whether to send an alert notification.
Properties:
DefaultTask: alarmNotify
Choices:
- When:
'Fn::Equals':
- []
- 'Fn::MergeList':
'Fn::MergeList': '{{ instanceThresholdInfo.thresholdInfos }}'
NextTask: 'ACS::END'
- Name: alarmNotify
Action: 'ACS::Notify'
Description:
en: Sends an alert notification that the instance discount or spot price exceeds the threshold.
zh-cn: Sends an alert notification that the instance discount or spot price exceeds the threshold.
Properties:
NotifyType: WebHook
WebHook:
URI: '{{ webhook }}'
Headers:
Content-Type: application/json
Content:
msgtype: markdown
markdown:
title: Monitoring Result
text:
'Fn::Join':
- ''
- 'Fn::ListJoin':
- |
### Alarm threshold: {{ threshold }}
- 'Fn::Jq':
- First
- '.[0] | split(", ") | join("") | split("||") | join("|") | split(",") | join("") | split("|###") | join("###")'
- 'Fn::Jq':
- All
- '.[] | map(.[] | tostring)| join(" |")'
- 'Fn::Jq':
- All
- 'map(. | .threshold=.threshold+" |\n\n,")'
- 'Fn::Jq':
- All
- '.[] | .scalingGroupId = "### Scaling group ID: "+.scalingGroupId+"\n| Instance type |  Zone|Current price|Discount (%)|\n|:----|----:|:----:|:----|\n,"'
- 'Fn::MergeList':
'Fn::MergeList': '{{ instanceThresholdInfo.thresholdInfos }}'
Outputs:
allThresholdInfo:
Type: List
Value:
'Fn::Join':
- ''
- 'Fn::ListJoin':
- |
### Alarm threshold: {{ threshold }}
- 'Fn::Jq':
- First
- '.[0] | split(", ") | join("") | split("||") | join("|") | split(",") | join("") | split("|###") | join("###")'
- 'Fn::Jq':
- All
- '.[] | map(.[] | tostring)| join(" |")'
- 'Fn::Jq':
- All
- 'map(. | .threshold=.threshold+" |\n\n,")'
- 'Fn::Jq':
- All
- '.[] | .scalingGroupId = "### Scaling group ID: "+.scalingGroupId+"\n| Instance type |  Zone|Current price|Discount (%)|\n|:----|----:|:----:|:----|\n,"'
- 'Fn::MergeList':
'Fn::MergeList': '{{ instanceThresholdInfo.thresholdInfos }}'
Metadata:
ALIYUN::OOS::Interface:
ParameterGroups:
- Parameters:
- region
- scalingGroupId
- taskType
- threshold
- webhook
Label:
default:
zh-cn: Configure Parameters
en: Configure Parameters
- Parameters:
- rateControl
- OOSAssumeRole
Label:
default:
zh-cn: Advanced Options
en: Advanced Options