调用ListPrometheusAlertRules接口查看Prometheus告警规则列表。

调试

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

请求参数

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

系统规定参数。取值:ListPrometheusAlertRules

Name String Prometheus_Alert

告警规则名称。

RegionId String cn-hangzhou

地域ID。

ClusterId String c0bad479465464e1d8c1e641b0afb****

集群ID。

Type String 自定义

告警规则类型。

Status Integer 1

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

  • 1:开启
  • 0:关闭
MatchExpressions String [{"key":"severity","value":"critical","operator":"re"}]

标签匹配条件的JSON串。关于此字段的详细说明参见下文关于参数MatchExpressions的补充说明

关于参数MatchExpressions的补充说明

JSON串示例及说明

[
{
    "key":"severity",                           // 标签的Key。
    "value":"critical",                           // 标签的Value。
    "operator":"re"                           // eq:等于;re:匹配正则。
}
]

返回数据

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

请求ID。

PrometheusAlertRules Array of PrometheusAlertRule

返回结构体。

Status Integer 1

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

  • 1:开启
  • 0:关闭
Type String 自定义

告警规则类型。

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,当NotifyType指定为DISPATCH_RULE时显示此参数。

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=ListPrometheusAlertRules
&ClusterId=c0bad479465464e1d8c1e641b0afb****
&RegionId=cn-hangzhou
&<公共请求参数>

正常返回示例

XML格式

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

<ListPrometheusAlertRulesResponse>
    <PrometheusAlertRules>
        <Status>1</Status>
        <NotifyType>ALERT_MANAGER</NotifyType>
        <Type>自定义</Type>
        <AlertId>3888704</AlertId>
        <AlertName>Prometheus_Alert</AlertName>
        <Message>${{$labels.pod_name}}CPU使用率大于80%,当前值{{$value}}%</Message>
        <ClusterId>c0bad479465464e1d8c1e641b0afb****</ClusterId>
        <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>
        <DispatchRuleId>10282</DispatchRuleId>
        <Duration>1m</Duration>
        <Labels>
            <Value>critical</Value>
            <Name>severity</Name>
        </Labels>
        <Annotations>
            <Value>${{$labels.pod_name}}CPU使用率大于80%,当前值{{$value}}%</Value>
            <Name>message</Name>
        </Annotations>
    </PrometheusAlertRules>
    <RequestId>9FEA6D00-317F-45E3-9004-7FB8B0B7****</RequestId>
</ListPrometheusAlertRulesResponse>

JSON格式

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

{
  "PrometheusAlertRules" : {
    "Status" : 1,
    "NotifyType" : "ALERT_MANAGER",
    "Type" : "自定义",
    "AlertId" : 3888704,
    "AlertName" : "Prometheus_Alert",
    "Message" : "${{$labels.pod_name}}CPU使用率大于80%,当前值{{$value}}%",
    "ClusterId" : "c0bad479465464e1d8c1e641b0afb****",
    "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",
    "DispatchRuleId" : 10282,
    "Duration" : "1m",
    "Labels" : {
      "Value" : "critical",
      "Name" : "severity"
    },
    "Annotations" : {
      "Value" : "${{$labels.pod_name}}CPU使用率大于80%,当前值{{$value}}%",
      "Name" : "message"
    }
  },
  "RequestId" : "9FEA6D00-317F-45E3-9004-7FB8B0B7****"
}

错误码

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