-
Notifications
You must be signed in to change notification settings - Fork 17
/
ACS::ECS::AlarmSpotPriceOrDiscountBySingleScalingGroup.json
261 lines (261 loc) · 7.73 KB
/
ACS::ECS::AlarmSpotPriceOrDiscountBySingleScalingGroup.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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
{
"FormatVersion": "OOS-2019-06-01",
"Description": {
"name-en": "ACS::ECS::AlarmSpotPriceOrDiscountBySingleScalingGroup",
"name-zh-cn": "监控单个伸缩组内实例的现价或折扣的阈值",
"en": "Alarm notification when spot instance discount or spot price exceeds threshold in the single scaling group existing instances",
"zh-cn": "监控弹性伸缩组弹出的预付费实例的最新价格与折扣,超出阈值时发出报警通知"
},
"Parameters": {
"regionId": {
"Description": {
"en": "The ID of region",
"zh-cn": "地域ID"
},
"Type": "String"
},
"threshold": {
"Description": {
"en": "The discount threshold(example:10 is 1% off, 50 is 50% off)",
"zh-cn": "折扣阈值(例:输入10是1折,50为5折)"
},
"Type": "Number"
},
"taskType": {
"Description": {
"en": "Monitoring threshold task type",
"zh-cn": "监控阈值的任务类型"
},
"Type": "String"
},
"scalingGroupId": {
"Description": {
"en": "The ID of scaling group",
"zh-cn": "弹性伸缩组ID"
},
"Type": "String"
}
},
"Tasks": [
{
"Name": "describeScalingInstances",
"Action": "ACS::ExecuteAPI",
"Description": {
"en": "Queries the scaling ECS instance IDs",
"zh-cn": "获取伸缩组内ECS实例的ID"
},
"Properties": {
"Service": "ESS",
"API": "DescribeScalingInstances",
"Parameters": {
"RegionId": "{{ regionId }}",
"ScalingGroupId": "{{ scalingGroupId }}"
}
},
"Outputs": {
"instanceIds": {
"Type": "List",
"ValueSelector": ".ScalingInstances.ScalingInstance[].InstanceId"
}
}
},
{
"Name": "wetherExistInstance",
"Action": "ACS::Choice",
"Description": {
"en": "Check wether an alarm notification is required",
"zh-cn": "检测是否需要发报警通知"
},
"Properties": {
"DefaultTask": "describeInstances",
"Choices": [
{
"When": {
"Fn::Equals": [
[],
"{{ describeScalingInstances.instanceIds }}"
]
},
"NextTask": "ACS::END"
}
]
}
},
{
"Name": "describeInstances",
"Action": "ACS::ExecuteAPI",
"Description": {
"en": "Queries instance type and zone of the ECS instance",
"zh-cn": "获取ECS实例的规格和可用区"
},
"Properties": {
"Service": "ECS",
"API": "DescribeInstances",
"Parameters": {
"RegionId": "{{ regionId }}",
"InstanceIds": [
"{{ ACS::TaskLoopItem }}"
]
}
},
"Outputs": {
"instanceTypeAndZone": {
"Type": "Json",
"ValueSelector": ".Instances.Instance[] | {\"instanceType\":.InstanceType, \"zoneId\": .ZoneId}"
}
},
"Loop": {
"Items": "{{ describeScalingInstances.instanceIds }}",
"MaxErrors": 100,
"Concurrency": 50,
"Outputs": {
"instanceTypeAndZones": {
"AggregateField": "instanceTypeAndZone",
"AggregateType": "Fn::ListJoin"
}
}
}
},
{
"Name": "describeScalingGroups",
"Action": "ACS::ExecuteAPI",
"Description": {
"en": "Queries the name of scaling group",
"zh-cn": "获取伸缩组名称"
},
"Properties": {
"Service": "ESS",
"API": "DescribeScalingGroups",
"Parameters": {
"RegionId": "{{ regionId }}",
"ScalingGroupId1": "{{ scalingGroupId }}"
}
},
"Outputs": {
"scalingGroupName": {
"Type": "String",
"ValueSelector": ".ScalingGroups.ScalingGroup[].ScalingGroupName"
}
}
},
{
"Name": "outPutSingleScalingGroupInfo",
"Action": "ACS::ECS::AlarmSpotPriceOrDiscountByScalingGroupInstance",
"Description": {
"en": "Monitor discounts or prices of all created spot instance types under a single scaling group",
"zh-cn": "监控单个伸缩组下所有预付费实例类型的折扣与价格"
},
"Properties": {
"regionId": "{{regionId}}",
"threshold": "{{ threshold }}",
"taskType": "{{ taskType }}",
"instanceType": {
"Fn::Jq": [
"First",
".instanceType",
"{{ ACS::TaskLoopItem }}"
]
},
"zoneId": {
"Fn::Jq": [
"First",
".zoneId",
"{{ ACS::TaskLoopItem }}"
]
}
},
"Outputs": {
"monitorInfo": {
"Type": "Json",
"ValueSelector": "discountInfo"
}
},
"Loop": {
"Items": {
"Fn::Jq": [
"First",
". | unique",
"{{ describeInstances.instanceTypeAndZones }}"
]
},
"MaxErrors": 100,
"Concurrency": 10,
"Outputs": {
"scalingGroupMonitorInfos": {
"AggregateField": "monitorInfo",
"AggregateType": "Fn::ListJoin"
}
}
}
}
],
"Outputs": {
"singleMonitorInfo": {
"Type": "String",
"Value": {
"Fn::If": [
{
"Fn::Equals": [
[],
{
"Fn::MergeList": [
"{{ outPutSingleScalingGroupInfo.scalingGroupMonitorInfos }}"
]
}
]
},
null,
{
"Fn::Jq": [
"First",
".[0] as $item | \"\\n### 伸缩组名称:{{describeScalingGroups.scalingGroupName}}\\n### 伸缩组ID:{{scalingGroupId}}\\n| 机型 |  可用区|现价|折扣%|\\n|:----|:----|:----:|:----|\\n\" + $item",
[
{
"Fn::Jq": [
"First",
".[]|split(\", \") | join(\"\") |split(\"\\n,\")| join(\"\")| split(\"\\n,|\")|join(\"\") |split(\"||\")|join(\"|\")",
{
"Fn::Jq": [
"All",
".[1]=\"\"|join(\"|\")",
{
"Fn::Jq": [
"All",
".[1]=\"\"| .[1]=.[0] | .[0]=\"\" | join(\"|\")",
{
"Fn::Jq": [
"All",
"map(.) | join(\"\\n|\")",
{
"Fn::Jq": [
"All",
".[] | map(.[] | tostring)| join(\" |\")",
{
"Fn::Jq": [
"All",
"map(.| .actualDiscount=.actualDiscount+\" |\\n,\" )",
{
"Fn::MergeList": [
"{{ outPutSingleScalingGroupInfo.scalingGroupMonitorInfos }}"
]
}
]
}
]
}
]
}
]
}
]
}
]
}
]
]
}
]
}
}
}
}