All Products
Search
Document Center

Application Real-Time Monitoring Service:CreatePrometheusAlertRule

Last Updated:Nov 05, 2024

Creates an alert rule.

Debugging

You can run this interface directly in OpenAPI Explorer, saving you the trouble of calculating signatures. After running successfully, OpenAPI Explorer can automatically generate SDK code samples.

Authorization information

The following table shows the authorization information corresponding to the API. The authorization information can be used in the Action policy element to grant a RAM user or RAM role the permissions to call this API operation. Description:

  • Operation: the value that you can use in the Action element to specify the operation on a resource.
  • Access level: the access level of each operation. The levels are read, write, and list.
  • Resource type: the type of the resource on which you can authorize the RAM user or the RAM role to perform the operation. Take note of the following items:
    • The required resource types are displayed in bold characters.
    • If the permissions cannot be granted at the resource level, All Resources is used in the Resource type column of the operation.
  • Condition Key: the condition key that is defined by the cloud service.
  • Associated operation: other operations that the RAM user or the RAM role must have permissions to perform to complete the operation. To complete the operation, the RAM user or the RAM role must have the permissions to perform the associated operations.
OperationAccess levelResource typeCondition keyAssociated operation
arms:CreatePrometheusAlertRulecreate
  • All Resources
    *
    none
none

Request parameters

ParameterTypeRequiredDescriptionExample
RegionIdstringYes

The ID of the region.

cn-hangzhou
AlertNamestringYes

The name of the alert rule.

Prometheus_Alert
ClusterIdstringYes

The ID of the cluster.

c0bad479465464e1d8c1e641b0afb****
TypestringNo

The type of the alert rule. Valid values:

  • 99: custom alert
  • 101: Prometheus Service alert
101
NotifyTypestringNo

The method that is used to send alert notifications. Valid values:

  • ALERT_MANAGER: Alert notifications are sent by Operation Center. This is the default value.
  • DISPATCH_RULE: Alert notifications are sent based on the specified notification policy.
ALERT_MANAGER
DispatchRuleIdlongNo

The ID of the notification policy. This parameter is required if the NotifyType parameter is set to DISPATCH_RULE.

10282
ExpressionstringYes

The expression of the alert rule. The expression must follow the 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
DurationstringYes

The duration. The value ranges from 1 to 1440 minutes.

10m
MessagestringYes

The content of the alert notification. Tags can be referenced in the {{$labels.xxx}} format.

The CPU utilization of ${{$labels.pod_name}} has exceeded 80%. Current value: {{$value}}%
LabelsstringNo

The tags that are described in a JSON string. You must specify the name and value of each tag.

[{"Value": "critical","Name": "severity"}]
AnnotationsstringNo

The annotations that are described in a JSON string. You must specify the name and value of each annotation.

[{"Value": "xxx","Name": "description"}]
Tagsarray<object>No

The tags.

objectNo

The tag.

KeystringNo

The tag key.

type
ValuestringNo

The tag value.

value1

Response parameters

ParameterTypeDescriptionExample
object
RequestIdstring

The ID of the request.

9FEA6D00-317F-45E3-9004-7FB8B0B7****
PrometheusAlertRuleobject

The returned struct.

Statusinteger

Indicates whether the alert rule is enabled. Valid values:

  • 1: The alert rule is enabled.
  • 0: The alert rule is disabled.
1
Typestring

The type of the alert rule.

Kubernetes component alert
NotifyTypestring

The method that is used to send alert notifications. Valid values:

  • ALERT_MANAGER: Alert notifications are sent by Operation Center.
  • DISPATCH_RULE: Alert notifications are sent based on the specified notification policy.
ALERT_MANAGER
Expressionstring

The expression of the alert rule.

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
Messagestring

The content of the alert notification. Tags can be referenced in the {{$labels.xxx}} format.

The CPU utilization of ${{$labels.pod_name}} has exceeded 80%. Current value: {{$value}}%
Durationstring

The duration. The value ranges from 1 to 1440 minutes.

10m
DispatchRuleIdlong

The ID of the notification policy.

10282
AlertNamestring

The name of the alert rule.

Prometheus_Alert
AlertIdlong

The ID of the alert rule.

3888704
ClusterIdstring

The ID of the cluster.

c0bad479465464e1d8c1e641b0afb****
Labelsarray<object>

The tags of the alert rule.

Labelobject

The tags of the alert rule.

Namestring

The name of the tag.

severity
Valuestring

The value of the tag.

critical
Annotationsarray<object>

The annotations of the alert rule.

Annotationobject

The annotation of the alert rule.

Namestring

The name of the annotation.

message
Valuestring

The value of the annotation.

The CPU utilization of ${{$labels.pod_name}} has exceeded 80%. Current value: {{$value}}%
Codelong

The HTTP status code. The status code 200 indicates that the request was successful.

200
Successboolean

Indicates whether the request was successful.

true
Messagestring

The returned message.

success

Examples

Sample success responses

JSONformat

{
  "RequestId": "9FEA6D00-317F-45E3-9004-7FB8B0B7****",
  "PrometheusAlertRule": {
    "Status": 1,
    "Type": "Kubernetes component alert\n",
    "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": "The CPU utilization of ${{$labels.pod_name}} has exceeded 80%. Current value: {{$value}}%\n",
    "Duration": "10m",
    "DispatchRuleId": 10282,
    "AlertName": "Prometheus_Alert",
    "AlertId": 3888704,
    "ClusterId": "c0bad479465464e1d8c1e641b0afb****",
    "Labels": [
      {
        "Name": "severity",
        "Value": "critical"
      }
    ],
    "Annotations": [
      {
        "Name": "message",
        "Value": "The CPU utilization of ${{$labels.pod_name}} has exceeded 80%. Current value: {{$value}}%"
      }
    ]
  },
  "Code": 200,
  "Success": true,
  "Message": "success"
}

Error codes

For a list of error codes, visit the Service error codes.

Change history

Change timeSummary of changesOperation
2023-07-31The response structure of the API has changedView Change Details
2023-05-11API Description Update. The request parameters of the API has changedView Change Details