All Products
Search
Document Center

Quota Center:Create a global alert rule for all API rate limits of a cloud service

Last Updated:Dec 05, 2024

If you want to monitor the rate limits of all API operations of a cloud service, you can create a global alert rule for all the API rate limits of the cloud service. This way, if the used quota or available quota of a monitored API rate limit reaches the specified threshold, an alert notification is sent to a relevant alert contact to remind the contact to increase the quota at the earliest opportunity.

Scenarios

When an enterprise manages cloud services, the enterprise may integrate the APIs of cloud services with their business to improve the automatic resource management capabilities. Due to the large number of API operations and frequent access to API operations, API throttling frequently occurs, which affects business stability. To resolve this issue, the O&M team of the enterprise can monitor the real-time usage and quotas of cloud service APIs and make plans in advance to ensure business stability. However, it is difficult to configure alert rules for each API operation separately because of the large number of API operations. In this case, the O&M team can use the global API rate limit monitoring feature.

Alibaba Cloud allows you to create a global alert rule for all API rate limits of a cloud service in the console or by calling API operations.

Billing

The alerting feature for API rate limits integrates the alerting capability of CloudMonitor. Alert notifications that are sent based on the created alert rules consume the notification quotas of CloudMonitor. The following billing rules apply based on the notification method:

  • Phone calls: No free quota is provided. You need to enable the pay-as-you-go billing mode or purchase resource plans. For more information, see Pay-as-you-go and Resource plans.

  • SMS messages: The free quota is 1,000 messages per month. You need to enable the pay-as-you-go billing mode or purchase resource plans if the free quota is used up. For more information, see Free quotas, Pay-as-you-go, and Resource plans.

  • Emails and alert callbacks: These two notification methods are both free of charge.

Before you begin

  • You must create an alert contact and an alert contact group in the CloudMonitor console to receive alert notifications. For more information, see Create an alert contact or alert contact group.

    image

  • If you to create alert rules for API rate limits a Resource Access Management (RAM) user, you must attach the AliyunQuotasFullAccess policy to the RAM user and grant the RAM user the permissions to create and delete alert rules for quota items by using CloudMonitor.

    Grant the following permissions to the RAM user. For more information, see Create custom policies and Grant permissions to a RAM user.

    {
      "Statement": [
        {
          "Effect": "Allow",
          "Action": [
            "cms:PutMetricRuleTargets",
            "cms:PutResourceMetricRules",
            "cms:DeleteMetricRules",
            "cms:DeleteMetricRuleTargets"
          ],
          "Resource": "*"
        }
      ],
      "Version": "1"
    }

Create a global alert rule for all API rate limits of a cloud service in the console

In this topic, a global alert rule is created for all API rate limits of Compute Nest. The alert condition is that if the quota usage of a monitored API rate limit reaches or exceeds 80%, alert notifications at the Warning level are sent to the alert contacts in the specified alert contact group by using text messages and emails.

You can perform this operation in the Quota Center console or the CloudMonitor console based on your business requirements.

Configure a global alert rule in the Quota Center console

  1. On the Products with API Rate Limits page of the Quota Center console, click Compute Nest in the Elastic Compute section.image

  2. On the page that appears, click Global alarm rules in the upper-right corner. On the Create Alarm Rule page, create a global alert rule for all API rate limits of Compute Nest.

    For more information about the parameters, see the "Parameters for creating an alert rule for an API rate limit" table in the Create an alert rule for a quota item topic.imageimage

  3. Check the created global alert rule.

    • Click Alarm Rules in the left-side navigation pane. On the Alarm Rules page, click the API Rate Limits tab. On the API Rate Limits tab, find the created alert rule.

      image

    • Click Monitoring Details in the Actions column. In the dialog box that appears, view the monitoring details of each monitored API operation.

      image

Configure a global alert rule in the CloudMonitor console

  1. On the Cloud Service Monitoring page of the CloudMonitor console, move the pointer over the Compute Nest section and click Compute Nest to go to the API rate quota tab.

    image

  2. On the API rate quota tab, click Global alarm rule in the upper-right corner. In the Global alarm rule panel, create a global alert rule for all API rate limits of Compute Nest.

    For more information about the parameters, see the "Parameters for creating an alert rule for an API rate limit" table in the Create an alert rule for a quota item topic.

    image

    image

  3. Check the created global alert rule.

    image

Create a global alert rule for all API rate limits of a cloud service by calling API operations

In this topic, a global alert rule is created for all API rate limits of Compute Nest. The alert condition is that if the quota usage of a monitored API rate limit reaches or exceeds 80%, alert notifications at the Warning level are sent to the alert contacts in the specified alert contact group by using text messages and emails.

  1. Check whether the API rate limits of Compute Nest support the global API rate limit monitoring feature.

    Call the ListProductQuotas operation of Quota Center and check the UsageMetric response parameter. If the return value of the UsageMetric parameter is not empty, Compute Nest supports the feature.

    • Request parameters: Set the ProductCode parameter to computenest and the QuotaCategory parameter to FlowControl, and use the default values for other parameters.

    • Response parameters: The UsageMetric response parameter displays the monitoring information for API rate limits in CloudMonitor. The return value of the MetricNamespace parameter is acs_quotas_flowcontrol. The following sample response shows the returned data for an API rate limit:

      {
            "QuotaDescription": "GetServiceTemplateParameterConstraints",
            "Consumable": false,
            "ProductCode": "computenest",
            "UsageMetric": {
              "MetricName": "Usage",
              "MetricDimensions": {
                "productCode": "computenest",
                "metricKey": "GetServiceTemplateParameterConstraints/2021-06-01",
                "regionId": "ap-southeast-1",
                "label": "none"
              },
              "MetricNamespace": "acs_quotas_flowcontrol"
            },
            "Dimensions": {
              "apiName": "GetServiceTemplateParameterConstraints",
              "apiVersion": "2021-06-01",
              "regionId": "ap-southeast-1"
            },
            "GlobalQuota": false,
            "Period": {
              "PeriodValue": 1,
              "PeriodUnit": "second"
            },
            "Adjustable": true,
            "QuotaActionCode": "f_4w8uhd",
            "QuotaName": "GetServiceTemplateParameterConstraints",
            "QuotaArn": "acs:quotas:ap-southeast-1:14133977********:quota/computenest/f_4w8uhd",
            "TotalQuota": 50,
            "QuotaCategory": "FlowControl"
          }
      Note

      The metricKey parameter can be used to create an alert rule for a single API rate limit.

  2. Call the DescribeMetricList operation of CloudMonitor to query the monitoring data of API rate limits. The quota usage trends shown in the monitoring data can be used for your reference when you create an alert rule.

    • Request parameters: Set the Namespace parameter to acs_quotas_flowcontrol, the MetricName parameter to UsagePercentage, and the Dimensions parameter to [{"productCode":"computenest"}], and use the default values for other parameters.

      Note

      The valid values of the MetricName parameter for Quota Center are Quota (monitors the quota value), Usage (monitors the used quota), UsagePercentage (monitors the percentage of the used quota), and AvailablePercentage (monitors the percentage of the remaining quota).

    • Response parameters: You can refer to the Value parameter in the Datapoints response parameter to specify a threshold. The following code provides a sample response:

      {
        "RequestId": "2A7DB5BF-825C-51BB-AD91-D728857792F9",
        "Period": "60",
        "Datapoints": "[{\"timestamp\":1727337180000,\"productCode\":\"computenest\",\"metricKey\":\"GetServiceTemplateParameterConstraints/2021-05-21\",\"regionId\":\"cn-hangzhou\",\"label\":\"none\",\"userId\":\"14133977********\",\"Value\":2.0}]",
        "Code": "200",
        "Success": true
      }
  3. Call the PutResourceMetricRules operation of CloudMonitor to create an alert rule for all API rate limits of Compute Nest.

    • Request parameters: The following table describes how to specify the required request parameters and provides examples.

      Parameter

      Description

      Example

      MetricName

      The name of the metric. Valid values:

      • Quota: monitors the quota value.

      • Usage: monitors the used quota.

      • UsagePercentage: monitors the percentage of the used quota.

      • AvailablePercentage: monitors the percentage of the remaining quota.

      Note

      Only UsagePercentage and AvailablePercentage are available for a global alert rule for API rate limits.

      UsagePercentage

      Escalations.Warn.Threshold

      The threshold for alerts at the Warning level.

      80

      EffectiveInterval

      The period during which the alert rule takes effect.

      00:00-23:59 +0800 dayofweek 1,2,3,4,5,6,7

      RuleId

      The ID of the alert rule.

      quota-computenest-ruleid-test

      Escalations.Warn.ComparisonOperator

      The operator that is used to compare the metric value with the threshold for alerts at the Warning level. Valid values:

      • GreaterThanOrEqualToThreshold: The metric value is greater than or equal to the threshold.

      • GreaterThanThreshold: The metric value is greater than the threshold.

      • LessThanOrEqualToThreshold: The metric value is less than or equal to the threshold.

      • LessThanThreshold: The metric value is less than the threshold.

      • NotEqualToThreshold: The metric value is not equal to the threshold.

      • GreaterThanYesterday: The metric value is greater than the metric value at the same time yesterday.

      • LessThanYesterday: The metric value is less than the metric value at the same time yesterday.

      • GreaterThanLastWeek: The metric value is greater than the metric value at the same time last week.

      • LessThanLastWeek: The metric value is less than the metric value at the same time last week.

      • GreaterThanLastPeriod: The metric value is greater than the metric value in the previous statistical period.

      • LessThanLastPeriod: The metric value is less than the metric value in the previous statistical period.

      GreaterThanOrEqualToThreshold

      Resources

      The resource information.

      Note

      The following sample code provides an example on how to specify the Resources parameter when you create an alert rule for a single API rate limit: [{"productCode":"computenest","metricKey":"GetServiceTemplateParameterConstraints/2021-06-01"}].

      [{"productCode":"computenest"}]

      ContactGroups

      The alert contact group.

      CloudMonitor

      Namespace

      The namespace of the cloud service.

      acs_quotas_flowcontrol

      RuleName

      The name of the alert rule.

      quota-computenest-rulename-test

      Escalations.Warn.Times

      The number of retries allowed for alerts at the Warning level.

      3

      Escalations.Warn.Statistics

      The statistical method for alerts at the Warning level.

      Value

    • If a response similar to the following one is returned, the alert rule is successfully created:

      {
        "Message": "",
        "RequestId": "BE4CAC0F-A134-55BA-909B-FF62568FE884",
        "FailedListResult": {
          "Target": []
        },
        "Code": "200",
        "Success": true
      }
  4. Call the DescribeMetricRuleList operation of CloudMonitor and check whether the alert rule is created from the RuleName or RuleId parameter.

What to do next