创建策略
功能介绍
该接口用于创建策略。- 策略名称必须为以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
参数 | 是否必选 | 参数类型 | 描述 |
|---|---|---|---|
project_id | 是 | String | 项目ID |
请求参数
参数 | 是否必选 | 参数类型 | 描述 |
|---|---|---|---|
resourcetype | 是 | String | 资源类型 示例:node |
Content-Type | 是 | String | 内容类型 该字段内容填为“application/json;charset=utf-8” 枚举值:
|
Cluster-Id | 是 | String | 集群ID |
Namespace | 是 | String | 命名空间 |
X-Auth-Token | 是 | String | 从IAM获取的用户Token。 |
Reserved-Info | 否 | String | 产品自定义字段 |
参数 | 是否必选 | 参数类型 | 描述 |
|---|---|---|---|
name | 是 | String | 策略名称 |
policy_type | 是 | String | 策略类型
枚举值:
|
group_id | 是 | String | 策略组id |
rule | 是 | AlarmRule object | 触发策略的规则 |
参数 | 是否必选 | 参数类型 | 描述 |
|---|---|---|---|
actions | 是 | Array of Action objects | 指定策略匹配成功后执行的动作。 |
conditions | 是 | Array of AlarmConditions objects | 匹配条件内容。一个规则可以有多个条件,多个条件之间的关系是“并且”,内部描述了多个详细匹配条件。一个条件可以描述一个metric的匹配方式。 |
参数 | 是否必选 | 参数类型 | 描述 |
|---|---|---|---|
type | 是 | String |
枚举值:
|
parameters | 是 | Array of Parameter objects | 包含扩缩容的实例数。 |
参数 | 是否必选 | 参数类型 | 描述 |
|---|---|---|---|
metric_namespace | 是 | String | 指标命名空间 枚举值:
|
metric_name | 是 | String | 指标名称 枚举值:
|
metric_unit | 是 | String | 单位 说明 随指标名称变化而变化,具体信息从AMS接口获取 |
period | 是 | Integer | 统计周期,单位:秒 枚举值:
|
evaluation_periods | 是 | Integer | 连续周期数 枚举值:
|
statistic | 是 | String | 统计方式 枚举值:
|
metric_operation | 是 | String | 指标操作符 包含“>”、“<”。 例如,“>”表示当metric大于metric_thresholdUpdate值时触发actions 枚举值:
|
metric_threshold | 是 | Integer | 阈值条件 |
响应参数
状态码: 200
参数 | 参数类型 | 描述 |
|---|---|---|
errorCode | String | 错误码 |
errorMessage | String | 详细信息 |
policy_id | String | 策略ID |
请求示例
周期策略示例
POST https://{EndPoint}/v1/{project_id}/pe/policy { "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 } } ] } }告警策略示例
POST https://{EndPoint}/v1/{project_id}/pe/policy { "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 } } ] } }定时策略示例
POST https://{EndPoint}/v1/{project_id}/pe/policy { "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 } } ] } }
响应示例
状态码: 200
OK
请求执行完成。
{
"errorCode" : "SVCSTG.PE.0",
"errorMessage" : "",
"policy_id" : "1b9994f0-847a-45e4-aeee-e8b604dddb34"
} 状态码
状态码 | 描述 |
|---|---|
200 | OK 请求执行完成。 |
400 | BadRequest 非法请求。建议直接修改该请求,不要重试该请求。 |
401 | Unauthorized 在客户端提供认证信息后,返回该状态码,表明服务端指出客户端所提供的认证信息不正确或非法。 |
403 | Forbidden 请求被拒绝访问。返回该状态码,表明请求能够到达服务端,且服务端能够理解用户请求,但是拒绝做更多的事情,因为该请求被设置为拒绝访问,建议直接修改该请求,不要重试该请求。 |
500 | InternalServerError 表明服务端能被请求访问到,但是不能理解用户的请求。 |
503 | ServiceUnavailable 被请求的服务无效。建议直接修改该请求,不要重试该请求。 |
错误码
请参见错误码。

