创建伸缩规则
更新时间:2026-07-22
描述
创建伸缩的伸缩规则,包括定时扩缩容、周期性扩缩容以及指标触发式的扩缩容。
OpenAPI Explorer
去调试
您可以在 OpenAPI Explorer 中直接运行该接口,免去您计算签名的困扰。运行成功后,OpenAPI Explorer 可以自动生成 SDK 代码示例。
请求结构
Plain Text
1POST /v1/rule
2Host: as.bj.baidubce.com
3Authorization: authorization string
4
5{
6 "ruleName": ruleName,
7 "groupId": groupId,
8 "state": state,
9 "type": type,
10 "actionType": actionType,
11 "actionNum": actionNum,
12 "cronTime": cronTime,
13 "cooldownInSec": cooldownInSec,
14 "periodType": periodType,
15 "periodValue": periodValue,
16 "periodStartTime": periodStartTime,
17 "periodEndTime": periodEndTime,
18 "asAlarmRule": {
19 "id": id,
20 "scope": scope,
21 "monitorObject": {
22 "type": type,
23 "names": [names],
24 "resources": [
25 {
26 "identifiers": [
27 {
28 "name": name,
29 "value": value
30 }
31 ],
32 "metricDimensions": [
33 {
34 "name": name,
35 "value": value
36 }
37 ]
38 }
39 ],
40 "typeName": typeName
41 },
42 "rules": [rules],
43 "alarmName": alarmName,
44 "aliasName": aliasName,
45 "insufficientCycle": insufficientCycle,
46 "policyEnabled": policyEnabled,
47 "ruleContents": [ruleContents],
48 "ruleContentsEn": [ruleContentsEn],
49 "source": source,
50 "componentType": componentType,
51 "alarmActions": [alarmActions],
52 "okActions": [okActions],
53 "insufficientActions": [insufficientActions]
54 }
55}
请求头域
除公共头域外,无其它特殊头域。
请求参数
| 参数名称 | 类型 | 是否必需 | 参数位置 | 描述 |
|---|---|---|---|---|
| ruleName | String | 是 | RequestBody参数 | 规则名称 |
| groupId | String | 是 | RequestBody参数 | 伸缩组id |
| state | state | 是 | RequestBody参数 | 创建后的规则状态。包括:ENABLE(启用),DISABLE(禁用) |
| type | type | 是 | RequestBody参数 | 规则类型。包括:CRONTAB(定时伸缩),ALARM(报警触发伸缩),PERIOD(周期伸缩) |
| actionType | actionType | 是 | RequestBody参数 | 动作类型。包括:INCREASE(扩容),DECREASE(缩容),ADJUST(调整至) |
| actionNum | Integer | 是 | RequestBody参数 | 动作数量 |
| cronTime | String | 否 | RequestBody参数 | 定时规则或周期规则:当日执行时间。如12:30。 |
| cooldownInSec | Integer | 是 | RequestBody参数 | 冷却时间(秒) |
| periodType | periodType | 否 | RequestBody参数 | 周期规则:周期单位,可选值为DAY/WEEK/MONTH/CronExpression |
| periodValue | Integer | 否 | RequestBody参数 | 周期规则:周期触发日期,1-7标识周1-周日,1-31表示1号到31号,与periodType相关 |
| periodStartTime | String | 否 | RequestBody参数 | 周期规则:周期有效期开始时间。如:2023-12-10T12:00:00Z |
| periodEndTime | String | 否 | RequestBody参数 | 周期规则:周期有效期结束时间。如:2023-12-11T12:00:00Z |
| asAlarmRule | AsAlarmRule | 否 | RequestBody参数 | 报警类规则:报警规则信息,详情见附录 |
返回头域
除公共头域,无其它特殊头域。
返回参数
| 参数名称 | 类型 | 描述 |
|---|---|---|
| ruleId | String | 规则ID |
请求示例,1
Plain Text
1POST /v1/rule
2Host: as.bj.baidubce.com
3Authorization: authorization string
4
5{
6 "ruleName" : "demo_rule",
7 "type" : "CRONTAB",
8 "actionType" : "ADJUST",
9 "actionNum" : "2",
10 "cooldownInSec" : 300,
11 "state" : "ENABLE",
12 "cronTime" : "11:11",
13 "groupId" : "asg-nJGIweB6"
14}
请求示例,2
Plain Text
1POST /v1/rule
2Host: as.bj.baidubce.com
3Authorization: authorization string
4
5{
6 "ruleName" : "demo_rule2",
7 "type" : "PERIOD",
8 "actionType" : "INCREASE",
9 "actionNum" : 1,
10 "cooldownInSec" : 300,
11 "state" : "ENABLE",
12 "periodType" : "MONTH",
13 "periodStartTime" : "2026-07-02T06:46:30Z",
14 "periodEndTime" : "2026-07-31T06:00:00Z",
15 "cronTime" : "11:11",
16 "periodValue" : 1,
17 "groupId" : "asg-nJxxxxxx"
18}
请求示例,3
Plain Text
1POST /v1/rule
2Host: as.bj.baidubce.com
3Authorization: authorization string
4
5{
6 "ruleName" : "demo_rule3",
7 "type" : "ALARM",
8 "actionType" : "INCREASE",
9 "actionNum" : 1,
10 "cooldownInSec" : 300,
11 "state" : "ENABLE",
12 "asAlarmRule" : {
13 "insufficientCycle" : 600,
14 "rules" : [ [ {
15 "metric" : "CPUUsagePercent",
16 "periodInSecond" : 60,
17 "statistics" : "average",
18 "comparisonOperator" : ">",
19 "threshold" : "60",
20 "index" : 1,
21 "evaluationPeriodCount" : 1,
22 "metricDimensions" : [ ]
23 } ] ],
24 "monitorObject" : {
25 "type" : "INSTANCE",
26 "names" : [ "InstanceId:asg-nJGIweB6" ],
27 "typeName" : "",
28 "resources" : [ {
29 "identifiers" : [ {
30 "name" : "InstanceId",
31 "value" : "asg-nJGIweB6"
32 } ],
33 "metricDimensions" : [ ]
34 } ]
35 },
36 "alarmActions" : [ "" ]
37 },
38 "groupId" : "asg-nJGIweB6"
39}
请求示例,4
Plain Text
1POST /v1/rule
2Host: as.bj.baidubce.com
3Authorization: authorization string
4
5{
6 "ruleName" : "bcmAlarm",
7 "type" : "ALARM",
8 "actionType" : "INCREASE",
9 "actionNum" : 1,
10 "cooldownInSec" : 60,
11 "state" : "ENABLE",
12 "asAlarmRule" : {
13 "insufficientCycle" : 600,
14 "alarmName" : "87a186bd3a684914xxxxxxxxxxxxxxxx",
15 "alarmActions" : [ "" ]
16 },
17 "groupId" : "asg-Y7xxxxxx"
18}
返回示例
Plain Text
1200 Success
评价此篇文章
