调用CreatePrometheusAlertRule接口创建告警规则。

调试

您可以在OpenAPI Explorer中直接运行该接口,免去您计算签名的困扰。运行成功后,OpenAPI Explorer可以自动生成SDK代码示例。

请求参数

名称 类型 是否必选 示例值 描述
Action String CreatePrometheusAlertRule

系统规定参数。取值:CreatePrometheusAlertRule

RegionId String cn-hangzhou

地域ID。

AlertName String Prometheus_Alert

告警规则名称。

ClusterId String c0bad479465464e1d8c1e641b0afb****

集群ID。

Type String Kubernetes组件告警

告警规则类型。

NotifyType String ALERT_MANAGER

通知类型。取值:

  • ALERT_MANAGER(默认):通过告警运维中心通知。
  • DISPATCH_RULE:指定通知策略进行通知。
DispatchRuleId Long 10282

通知策略ID,当NotifyType指定为DISPATCH_RULE时必填。

Expression String 100 * (sum(rate(container_cpu_usage_seconds_total[1m])) by (pod_name) / sum(label_replace(kube_pod_container_resource_limits_cpu_cores, \"pod_name\", \"$1\", \"pod\", \"(.*)\")) by (pod_name))>75

告警表达式,需要使用PromQL语句。

Duration String 1m

持续时间,范围在1m~1440m,单位为分钟。

Message String ${{$labels.pod_name}}CPU使用率大于80%,当前值{{$value}}%

告警消息,支持按照{{$labels.xxx}}格式来引用标签。

Labels String [{"Value": "critical","Name": "severity"}]

标签JSON串。需要设置标签的Name和Value。

Annotations String [{"Value": "xxx","Name": "description"}]

注释JSON串。需要设置注释的Name和Value。

返回数据

名称 类型 示例值 描述
RequestId String 9FEA6D00-317F-45E3-9004-7FB8B0B7****

请求ID。

PrometheusAlertRule Object

返回结构体。

Status Integer 1

告警规则启用状态。取值:

  • 1:开启。
  • 0:关闭。
Type String Kubernetes组件告警

告警规则类型。

NotifyType String ALERT_MANAGER

通知类型。取值:

  • ALERT_MANAGER:通过告警运维中心通知。
  • DISPATCH_RULE:指定通知策略进行通知。
Expression String 100 * (sum(rate(container_cpu_usage_seconds_total[1m])) by (pod_name) / sum(label_replace(kube_pod_container_resource_limits_cpu_cores, \"pod_name\", \"$1\", \"pod\", \"(.*)\")) by (pod_name))>75

告警表达式。

Message String ${{$labels.pod_name}}CPU使用率大于80%,当前值{{$value}}%

告警消息,支持按照{{$labels.xxx}}格式来引用标签。

Duration String 1m

持续时间,范围在1m~1440m,单位为分钟。

DispatchRuleId Long 10282

通知策略ID。

AlertName String Prometheus_Alert

告警规则名称。

AlertId Long 3888704

告警规则ID。

ClusterId String c0bad479465464e1d8c1e641b0afb****

集群ID。

Labels Array of Label

告警规则的标签。

Name String severity

标签的名称。

Value String critical

标签的值。

Annotations Array of Annotation

告警规则的注释。

Name String message

注释的名称。

Value String ${{$labels.pod_name}}CPU使用率大于80%,当前值{{$value}}%

注释的值。

示例

请求示例

http(s)://[Endpoint]/?Action=CreatePrometheusAlertRule
&RegionId=cn-hangzhou
&AlertName=Prometheus_Alert
&ClusterId=c0bad479465464e1d8c1e641b0afb****
&Type=Kubernetes组件告警
&NotifyType=ALERT_MANAGER
&DispatchRuleId=10282
&Expression=100 * (sum(rate(container_cpu_usage_seconds_total[1m])) by (pod_name) / sum(label_replace(kube_pod_container_resource_limits_cpu_cores, \"pod_name\", \"$1\", \"pod\", \"(.*)\")) by (pod_name))>75
&Duration=1m
&Message=${{$labels.pod_name}}CPU使用率大于80%,当前值{{$value}}%
&Labels=[{"Value": "critical","Name": "severity"}]
&Annotations=[{"Value": "xxx","Name": "description"}]
&公共请求参数

正常返回示例

XML格式

HTTP/1.1 200 OK
Content-Type:application/xml

<CreatePrometheusAlertRuleResponse>
    <RequestId>9FEA6D00-317F-45E3-9004-7FB8B0B7****</RequestId>
    <PrometheusAlertRule>
        <Status>1</Status>
        <Type>Kubernetes组件告警</Type>
        <NotifyType>ALERT_MANAGER</NotifyType>
        <Expression>100 * (sum(rate(container_cpu_usage_seconds_total[1m])) by (pod_name) / sum(label_replace(kube_pod_container_resource_limits_cpu_cores, \"pod_name\", \"$1\", \"pod\", \"(.*)\")) by (pod_name))&amp;gt;75</Expression>
        <Message>${{$labels.pod_name}}CPU使用率大于80%,当前值{{$value}}%</Message>
        <Duration>1m</Duration>
        <DispatchRuleId>10282</DispatchRuleId>
        <AlertName>Prometheus_Alert</AlertName>
        <AlertId>3888704</AlertId>
        <ClusterId>c0bad479465464e1d8c1e641b0afb****</ClusterId>
        <Labels>
            <Name>severity</Name>
            <Value>critical</Value>
        </Labels>
        <Annotations>
            <Name>message</Name>
            <Value>${{$labels.pod_name}}CPU使用率大于80%,当前值{{$value}}%</Value>
        </Annotations>
    </PrometheusAlertRule>
</CreatePrometheusAlertRuleResponse>

JSON格式

HTTP/1.1 200 OK
Content-Type:application/json

{
  "RequestId" : "9FEA6D00-317F-45E3-9004-7FB8B0B7****",
  "PrometheusAlertRule" : {
    "Status" : 1,
    "Type" : "Kubernetes组件告警",
    "NotifyType" : "ALERT_MANAGER",
    "Expression" : "100 * (sum(rate(container_cpu_usage_seconds_total[1m])) by (pod_name) / sum(label_replace(kube_pod_container_resource_limits_cpu_cores, \\\"pod_name\\\", \\\"$1\\\", \\\"pod\\\", \\\"(.*)\\\")) by (pod_name))&amp;gt;75",
    "Message" : "${{$labels.pod_name}}CPU使用率大于80%,当前值{{$value}}%",
    "Duration" : "1m",
    "DispatchRuleId" : 10282,
    "AlertName" : "Prometheus_Alert",
    "AlertId" : 3888704,
    "ClusterId" : "c0bad479465464e1d8c1e641b0afb****",
    "Labels" : {
      "Name" : "severity",
      "Value" : "critical"
    },
    "Annotations" : {
      "Name" : "message",
      "Value" : "${{$labels.pod_name}}CPU使用率大于80%,当前值{{$value}}%"
    }
  }
}

错误码

访问错误中心查看更多错误码。