All Products
Search
Document Center

Configure alerting for APIs

Last Updated: Aug 18, 2021

You can use Cloud Monitor to configure alerting for APIs that are published to API Gateway. This allows you to track the running status of APIs at all times and ensure the stability of API Gateway.

1. Associate alert rules with APIs

The monitoring and alerting feature of API Gateway can meet your various business requirements. API Gateway monitors the following items:

  • HttpStatusCode

  • Response time of an API

  • Number of requests for an API

  • Inbound traffic

  • Outbound traffic

You can use one of the following methods to create alert rules and associate the rules with APIs:

  • Associate alert rules with a single API or multiple APIs that reside in the same region. This method is used if you want to configure alert rules for a single API or the same alert rules for multiple APIs that reside in the same region. The alert rules are not affected even if API configurations are modified.

  • Associate alert rules with an API group. This method is used if you want to configure the same alert rules for all APIs in an API group. If you want to add, delete, or modify APIs in an API group, the system automatically updates alert rules for the API group.

  • Associate alert rules with all APIs under your Alibaba Cloud account. This method is used if you have only a few APIs that need to be managed.

Note

If you use the first or second method, you can select a specific environment, such as RELEASE, PRE, or TEST, to configure monitoring and alerting for APIs.

2. Configure alerting levels and methods

Cloud Monitor allows you to configure three alerting levels: Critical, Warning, and Info. The alert notifications of the three levels are sent by using different methods. For more information about alert notifications, see Overview.

  • Critical: phone calls, text messages, emails, and DingTalk ChatBot (use after payment)

  • Warning: text messages, emails, and DingTalk ChatBot

  • Info: emails and DingTalk ChatBot

Alert rules
Note

The preceding figure shows a sample alert rule. If the number of 2XX status codes that are returned each minute exceeds 200 for five consecutive minutes, the system sends an alert notification.

3. Configure alert rules for one or more APIs

You must configure alert templates, specific rules, alert contacts, and notifications. For more information, see Overview.

1. Log on to the API Gateway console. In the top navigation bar, select a region. In the left-side navigation pane, choose Publish APIs > APIs. On the API List page, find the API for which you want to configure alert rules and click its name.

2. In the left-side navigation pane of the page that appears, click Monitoring Info. On the page that appears, click Alarm Settings in the upper-right corner to go to the Cloud Monitor console.

Alarm Settings

3. On the page that appears, click Create Alert Rule. On the Create Alert Rule page, set Resource Range to API Dimensions. In the API field, you can specify one or more APIs with which you want to associate alert rules.

Set alert rules

4. Configure alert rules for an API group

1. To apply the same alert rules to all APIs in an API group, perform the following steps: In the left-side navigation pane, choose Publish APIs > API Groups. On the Group List page, find the API group for which you want to configure alert rules and click its name. On the Group Details page, click Turn on cloud monitoring in the upper-right corner.

Turn on cloud monitoring

2. If you enable the cloud monitoring feature for an API group for the first time, you must create an AliyunServiceRoleForApiGatewayMonitoring service-linked role in the dialogue box that appears.

3. Click OK. Then, the system displays the "Group cloud monitoring is successfully turned on" message. This message contains the name of a monitoring group. This monitoring group is created by API Gateway after being authorized by users. This monitoring group corresponds to the current API group. The format of the monitoring group name is APIGATEWAY_${region}_${groupId}. The region field indicates the region where the API group resides. The groupId field indicates the ID of the API group.

Apply alert rules

4. After you enable cloud monitoring, click Click to jump to cloud monitoring configuration in the upper-right corner of the Group Details page. On the page that appears, you can configure alert rules for the current API group.

Configure cloud monitoring

5. Configure alert rules for all APIs

The steps are similar to those in Section 3. However, you must set Resource Range to All Resources. After that, all APIs that are published to API Gateway in the current region use the same alert rules.

6. Configure alert rules supported by API Gateway

API Gateway monitors the following items for APIs: HTTP status code, response time of an API, number of requests for an API, inbound traffic, and outbound traffic. You can configure alert rules based on these items.

  • Response time of an API: the response time of a backend service of API Gateway.

  • Number of requests for an API: the total number of requests that are received by API Gateway for a specific API from clients within a specific period.

  • Inbound traffic: the traffic of requests that are received by API Gateway from clients within a specific period.

  • Outbound traffic: the traffic of requests that are sent to the backend services of API Gateway within a specific period.

  • HTTP status code: the status code that is returned by API Gateway. The state codes include 2XX, 4XX, and 5XX codes.

-Code2XX: The request for an API is successful. Note: A successful request does not mean that the service is successful.

-Code4XX: An error occurs on the client, such as a parameter error.

-Code5XX: An error occurs on a backend service. Users must pay close attention to such errors.

7. Usage notes

  • We recommend that users whose API groups reside in the classic network apply alert rules that are marked with Old and users whose API groups reside in a virtual private cloud (VPC) use alert rules that are not marked with Old.

  • You can configure alert rules based on the network environment where your APIs are published. If the alert rules configured for an API that is published in a VPC do not take effect, you can log on to the API Gateway console to go to the API monitoring information page. Then, check whether the monitoring data of the API can be queried based on the network environment. If not, submit a ticket to upgrade the version of your API Gateway.