forked from aliyun/oos-templates
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathACS::ECS::AlarmSpotPriceOrDiscountByScalingGroupInstance.json
171 lines (171 loc) · 4.84 KB
/
ACS::ECS::AlarmSpotPriceOrDiscountByScalingGroupInstance.json
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
{
"FormatVersion": "OOS-2019-06-01",
"Description": "Alarm notification when spot instance discount or spot price exceeds threshold in the scaling group existing instances.",
"Parameters": {
"regionId": {
"Description": "The region id.",
"Type": "String"
},
"threshold": {
"Description": "The discount threshold(example:10 is 1% off, 50 is 50% off).",
"Type": "Number"
},
"taskType": {
"Description": "Monitoring threshold task type.",
"Type": "String"
},
"instanceType": {
"Description": "The instance type.",
"Type": "String"
},
"zoneId": {
"Description": "The zone id.",
"Type": "String"
}
},
"Tasks": [
{
"Name": "describeSpotPriceHistoryInfos",
"Action": "ACS::ExecuteAPI",
"Description": "Get the latest discounts on spot instance.",
"Properties": {
"Service": "ECS",
"API": "DescribeSpotPriceHistory",
"Parameters": {
"RegionId": "{{ regionId }}",
"InstanceType": "{{ instanceType }}",
"NetworkType": "vpc",
"ZoneId": "{{ zoneId }}"
}
},
"Outputs": {
"discountAndPrice": {
"Type": "Json",
"ValueSelector": ".SpotPrices.SpotPriceType[-1] | {\"realThreshold\":(.SpotPrice / .OriginPrice * 100), \"spotPrice\":.SpotPrice, \"originPrice\":.OriginPrice, \"instanceType\":.InstanceType}"
}
}
},
{
"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 }}",
"{{ describeSpotPriceHistoryInfos.discountAndPrice }}"
]
}
]
},
"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 }}",
"{{ describeSpotPriceHistoryInfos.discountAndPrice }}"
]
}
]
},
"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": "{{ instanceType }}",
"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": {
"instanceType": "{{ describeSpotPriceHistory.instanceType }}",
"zoneId": "{{ describeSpotPriceHistory.zoneId }}",
"spotPrice": "{{ describeSpotPriceHistory.spotPrice }}",
"actualDiscount": "\"{{ describeSpotPriceHistory.actualDiscount }}\""
}
}
}
}