forked from aliyun/oos-templates
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathACS::ECS::AlarmScalingThreshold.yml
103 lines (103 loc) · 3.14 KB
/
ACS::ECS::AlarmScalingThreshold.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
FormatVersion: OOS-2019-06-01
Description: Alarm notification when spot instance discount or spot price exceeds threshold.
Parameters:
regionId:
Description: The region id.
Type: String
zoneId:
Description: The zone id.
Type: String
discountJsonInfo:
Description: The discount info.
Type: Json
threshold:
Description: The discount or price threshold.
Type: Number
scalingGroupId:
Description: The scaling group id.
Type: String
taskType:
Description: The monitoring threshold task type.
Type: String
Tasks:
- Name: selectTask
Action: 'ACS::Choice'
Description: Select the type of task that performs the monitoring threshold.
Properties:
DefaultTask: 'ACS::END'
Choices:
- When:
'Fn::Equals':
- Discount
- '{{ taskType }}'
NextTask: checkDiscountThreshold
- When:
'Fn::Equals':
- Price
- '{{ taskType }}'
NextTask: checkSpotPriceThreshold
- Name: checkDiscountThreshold
Action: 'ACS::Choice'
Description: Check if the actual discount exceeds the threshold.
Properties:
DefaultTask: 'ACS::END'
Choices:
- When:
'Fn::Equals':
- true
- 'Fn::Jq':
- First
- '.realThreshold >= {{ threshold }}'
- '{{ discountJsonInfo }}'
NextTask: describeSpotPriceHistory
- Name: checkSpotPriceThreshold
Action: 'ACS::Choice'
Description: Check if the actual discount exceeds the threshold.
Properties:
DefaultTask: 'ACS::END'
Choices:
- When:
'Fn::Equals':
- true
- 'Fn::Jq':
- First
- '.spotPrice >= {{ threshold }}'
- '{{ discountJsonInfo }}'
NextTask: describeSpotPriceHistory
- Name: describeSpotPriceHistory
Action: 'ACS::ExecuteAPI'
Description: Get the latest discounts or spot price on spot instance.
Properties:
Service: ECS
API: DescribeSpotPriceHistory
Parameters:
RegionId: '{{ regionId }}'
InstanceType:
'Fn::Jq':
- First
- .instanceType
- '{{ discountJsonInfo }}'
NetworkType: vpc
ZoneId: '{{ zoneId }}'
Outputs:
spotPrice:
Type: String
ValueSelector: '.SpotPrices.SpotPriceType[-1].SpotPrice'
instanceType:
Type: String
ValueSelector: '.SpotPrices.SpotPriceType[-1].InstanceType'
zoneId:
Type: String
ValueSelector: '.SpotPrices.SpotPriceType[-1].ZoneId'
actualDiscount:
Type: String
ValueSelector: '.SpotPrices.SpotPriceType[-1] | .SpotPrice / .OriginPrice * 10000 | floor as $num | $num/100'
Outputs:
discountInfo:
Type: Json
Value:
scalingGroupId: '{{ scalingGroupId }}'
instanceType: '{{ describeSpotPriceHistory.instanceType }}'
zoneId: '{{ describeSpotPriceHistory.zoneId }}'
spotPrice: '{{ describeSpotPriceHistory.spotPrice }}'
actualDiscount: '{{ describeSpotPriceHistory.actualDiscount }}'