Creates a Prometheus alert rule for a specified cluster.
Operation description
Use CreateOrUpdateAlertRule instead to create Prometheus alert rules.
Try it now
Test
RAM authorization
Request parameters
|
Parameter |
Type |
Required |
Description |
Example |
| RegionId |
string |
Yes |
The region ID of the cluster. |
cn-hangzhou |
| AlertName |
string |
Yes |
The name of the alert rule. |
Prometheus_Alert |
| ClusterId |
string |
Yes |
The cluster ID. |
c0bad479465464e1d8c1e641b0afb**** |
| Type |
string |
No |
The type of the alert rule. Valid values:
|
101 |
| NotifyType |
string |
No |
The notification method. Valid values:
|
ALERT_MANAGER |
| DispatchRuleId |
integer |
No |
The ID of the notification policy. This parameter is required when NotifyType is set to |
10282 |
| Expression |
string |
Yes |
The alert rule expression, which must follow PromQL syntax. |
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 |
string |
Yes |
The duration of the alert condition before the alert is triggered. Valid values: 1 to 1440. Unit: minutes. |
10m |
| Message |
string |
Yes |
The content of the alert notification message. You can reference tags in the {{$labels.xxx}} format. |
${{$labels.pod_name}}CPU使用率大于80%,当前值{{$value}}% |
| Labels |
string |
No |
The tags of the alert rule in JSON format. Specify the name and value of each tag. |
[{"Value": "critical","Name": "severity"}] |
| Annotations |
string |
No |
The annotations of the alert rule in JSON format. Specify the name and value of each annotation. |
[{"Value": "xxx","Name": "description"}] |
| Tags |
array<object> |
No |
The tags of the alert rule. |
|
|
object |
No |
The tag. |
||
| Key |
string |
No |
The tag key. |
type |
| Value |
string |
No |
The tag value. |
value1 |
Response elements
|
Element |
Type |
Description |
Example |
|
object |
|||
| RequestId |
string |
The request ID. |
9FEA6D00-317F-45E3-9004-7FB8B0B7**** |
| PrometheusAlertRule |
object |
The details of the alert rule. |
|
| Status |
integer |
Indicates whether the alert rule is enabled. Valid values:
|
1 |
| Type |
string |
The type of the alert rule. |
Kubernetes组件告警 |
| NotifyType |
string |
The notification method. Valid values:
|
ALERT_MANAGER |
| Expression |
string |
The alert rule 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 |
| Message |
string |
The content of the alert notification message. Tags can be referenced in the {{$labels.xxx}} format. |
${{$labels.pod_name}}CPU使用率大于80%,当前值{{$value}}% |
| Duration |
string |
The duration of the alert condition. Valid values: 1 to 1440. Unit: minutes. |
10m |
| DispatchRuleId |
integer |
The ID of the notification policy. |
10282 |
| AlertName |
string |
The name of the alert rule. |
Prometheus_Alert |
| AlertId |
integer |
The ID of the alert rule. |
3888704 |
| ClusterId |
string |
The cluster ID. |
c0bad479465464e1d8c1e641b0afb**** |
| Labels |
array<object> |
The tags of the alert rule. |
|
|
object |
The tag. |
||
| Name |
string |
The tag name. |
severity |
| Value |
string |
The tag value. |
critical |
| Annotations |
array<object> |
The annotations of the alert rule. |
|
|
object |
The annotation. |
||
| Name |
string |
The annotation name. |
message |
| Value |
string |
The annotation value. |
${{$labels.pod_name}}CPU使用率大于80%,当前值{{$value}}% |
| Code |
integer |
The HTTP status code. A value of 200 indicates success. |
200 |
| Success |
boolean |
Indicates whether the request was successful. |
true |
| Message |
string |
The response message. |
success |
Examples
Success response
JSON format
{
"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))>75",
"Message": "${{$labels.pod_name}}CPU使用率大于80%,当前值{{$value}}%",
"Duration": "10m",
"DispatchRuleId": 10282,
"AlertName": "Prometheus_Alert",
"AlertId": 3888704,
"ClusterId": "c0bad479465464e1d8c1e641b0afb****",
"Labels": [
{
"Name": "severity",
"Value": "critical"
}
],
"Annotations": [
{
"Name": "message",
"Value": "${{$labels.pod_name}}CPU使用率大于80%,当前值{{$value}}%"
}
]
},
"Code": 200,
"Success": true,
"Message": "success"
}
Error codes
See Error Codes for a complete list.
Release notes
See Release Notes for a complete list.