创建策略
功能说明
该接口用于创建策略。
- 策略名称必须为以0~9、a~z、A~Z、下划线(_)或中划线(-)组成的1~64位字符串,且必须以字母开头。
- 同一伸缩组下的策略,相同指标(metric_name)的metric_operation为“>”的metric_threshold值必须比metric_operation为“<”的metric_threshold值大。
- 同一伸缩组,相同指标只能创建一条metric_operation相同的告警策略。
- 同一策略的同名指标(metric_name),各条件(conditions)之间需保证逻辑不冲突。
- 定时策略的触发时间(launch_time)年份不能大于2099。
- 周期策略的开始时间(start_time)、结束时间(end_time)年份不能大于2099。
- 同一伸缩组下,支持创建定时策略和周期策略的总数最大为10个,支持创建最多10个告警策略。
- 同一伸缩组下,告警策略之间互不影响。
URI
POST /v1/{project_id}/pe/policy
请求消息
请求消息头
请求消息头如表1所示。
参数 | 描述 | 是否为必选 | 示例 |
|---|---|---|---|
Deployment-Name | 应用名称 | 必选 | - |
Content-Type | 内容类型 该字段内容填为“application/json;charset=utf-8” | 必选 | application/json;charset=utf-8 |
Cluster-Id | 集群ID | 必选 | - |
Namespace | 命名空间 | 必选 | - |
X-Auth-Token | 从IAM服务获取的用户Token。 | 必选 | - |
Reserved-Info | 产品自定义字段 | 可选 | - |
请求参数
请求参数如表2所示。
参数名称 | 是否必选 | 参数类型 | 取值范围 | 描述 |
|---|---|---|---|---|
name | 是 | String | 策略名称必须为以0~9、a~z、A~Z、下划线(_)或中划线(-)组成的1~64位字符串,且必须以字母开头。 | 策略名称 |
policy_type | 是 | String |
| 策略类型 |
rule | 是 | 参见表3 | - | 触发策略的规则 |
参数名称 | 是否必选 | 参数类型 | 取值范围 | 描述 |
|---|---|---|---|---|
conditions | 是 | 参见表4 | conditions只能有1个 | 匹配条件具体内容。 如果是告警策略,则多个策略的condition条件不能有重合,如:同一指标不能既大于10%,又小于20% |
actions | 是 | 参见表5 | actions只能有1个 | 指定策略匹配成功后执行的动作。 |
参数名称 | 是否必选 | 参数类型 | 取值范围 | 描述 |
|---|---|---|---|---|
launch_time | 是 | String | - | 触发时间,遵循ISO8601,UTC。
|
recurrence_type | 是 | String | 可取值为:Daily、Weekly、Monthly
| 周期触发类型 |
recurrence_value | 是 | String |
| 周期触发任务数值 |
start_time | 是 | String | - | 周期策略重复执行开始时间,遵循ISO8601,UTC,默认立即开始,格式为 : YYYY-MM-DDThh:mmZ。 |
end_time | 是 | String | - | 周期策略重复执行结束时间,遵循ISO8601,UTC,格式为 : YYYY-MM-DDThh:mmZ。 |
metric_namespace | 是 | String |
| 命名空间 |
metric_name | 是 | String | 取值满足表达式[a-zA-Z_:][a-zA-Z0-9_:]*,即指标名称首字符必须为字母或_或:,其他字符由字母数字_:组成,长度为1~255个字符。 | 指标名称 |
metric_unit | 是 | String | - | 单位 |
period | 是 | Integer | 分别包括20,60,300,900,1800,3600 | 统计周期,单位:秒 |
evaluation_periods | 是 | Integer | 1,2,3,4,5 | 连续周期数 |
statistic | 是 | String | 当前只支持平均值(average) | 统计方式 |
metric_operation | 是 | String | 包含“>”、“<”。 例如,“>”表示当metric大于metric_thresholdUpdate值时触发actions | 指标操作符 |
metric_threshold | 是 | Float | [0,2147483647] | 阈值条件 |
"conditions":[{
"metric_namespace" : "PAAS.CONTAINER",
"metric_name" : "cpuUsage",
"metric_unit" : "Percent",
"period" : 300,
"evaluation_periods" : 2,
"statistic" : "average",
"metric_operation" : ">",
"metric_threshold" : 70
}] 当应用指标(metric_namespace)为cpuUsage(metric_name)时,应用在连续2(evaluation_periods)个周期(周期时长:300秒)内平均值(statistic)值超过70%(metric_threshold)时触发策略。
参数名称 | 是否必选 | 参数类型 | 取值范围 | 描述 |
|---|---|---|---|---|
type | 是 | String |
|
含有k8s的表示容器应用,含有vm的表示进程应用。 |
parameters | 是 | 参见表6 | - | 包含扩缩容的实例数 |
请求示例
- 定时策略示例
{ "name" : "policy1", "policy_type" : "SCHEDULED", "rule" : { "conditions" : [{ "launch_time" : "2017-03-04T03:37Z", "recurrence_type" : null, "recurrence_value" : null, "start_time" : null, "end_time" : null } ], "actions" : [{ "type" : "scale_set_k8s", "parameters" : { "scale_unit" : 1 } } ] } } - 周期策略示例
{ "name" : "policy_2", "policy_type" : "RECURRENCE", "rule" : { "conditions" : [{ "launch_time" : "13:45", "recurrence_type" : "Weekly", "recurrence_value" : "0,1,4", "start_time" : "2017-01-26T03:33Z", "end_time" : "2099-01-31T03:33Z" } ], "actions" : [{ "type" : "scale_set_k8s", "parameters" : { "scale_unit" : 1 } } ] } } - 告警策略示例
{ "name" : "policy_1", "policy_type" : "ALARM", "rule" : { "conditions" : [{ "metric_namespace" : "PAAS.CONTAINER", "metric_name" : "cpuUsage", "metric_unit" : "Percent", "period" : 60, "evaluation_periods" : 1, "statistic" : "average", "metric_operation" : ">", "metric_threshold" : 70 } ], "actions" : [{ "type" : "scale_out_k8s", "parameters" : { "scale_unit" : 1 } } ] } }
响应消息
响应参数
响应参数如表7所示。
响应示例
{
"errorCode": 0,
"errorMessage": "",
"policy_id": "1b9994f0-847a-45e4-aeee-e8b604dddb34"
} 错误码
错误码 | 错误信息 | 处理措施 |
|---|---|---|
SVCSTG.PE.4001101 | Invalid parameter. | 请检查对应的参数是否符合要求。 |
SVCSTG.PE.4031012 | Failed to verify the project ID. | 请检查对应的参数是否符合要求。 |
SVCSTG.PE.5001201 | Failed to insert or update data in the background. | 请联系技术支持工程师解决。 |

