All Products
Search
Document Center

API Gateway:Configure alerting for APIs

Last Updated:Aug 23, 2023

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

1. Associate resources

The monitoring and alerting feature of API Gateway can meet various business requirements. API Gateway supports the following monitoring metrics:

  • HttpStatusCode

  • Response time of an API

  • Total number of requests for an API

  • Inbound traffic

  • Outbound traffic

You can use one of the following methods to create an alert rule and associate the alert rule with one or more APIs:

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

  • Associate an alert rule with an API group. This method is applicable to scenarios in which you want to configure the same alert rule for all APIs in an API group to monitor calls for the APIs. If you add, delete, or modify APIs in an API group, the system synchronizes the change between the API group and the alert rule.

  • Associate an alert rule with all API Gateway APIs that belong to your Alibaba Cloud account. This method is applicable to scenarios in which you want to manage only a small number of APIs.

Note

If you use the first or second method, you can select a specific environment in which you want to create an alert rule to configure monitoring and alerting for APIs. For example, you can select a production, staging, or test environment.

2. Configure alert levels and methods

Cloud Monitor allows you to configure the following types of alert levels: Critical, Warning, and Info. The methods that Cloud Monitor uses to send alert notifications vary based on the alerting levels. For more information about alert notifications, see Overview.

  • Critical: The system sends alert notifications by phone calls, text messages, emails, and DingTalk chatbots. You can use DingTalk chatbots only after you pay for them.

  • Warning: The system sends alert notifications by text messages, emails, and DingTalk chatbots.

  • Info: The system sends alert notifications by emails and DingTalk chatbots.

Configure an alert rule
Note

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

3. Associate an alert rule with one or more APIs

When you associate an alert rule with one or more APIs, you can configure the alert template, alert rule, alert contacts, and alert notifications. For more information, see Overview.

3.1 Log on to the API Gateway console. In the top navigation bar, select the region in which the API that you want to manage resides. In the left-side navigation pane, choose OpenAPI > APIs. On the APIs page, find the API with which you want to associate an alert rule and click the name of the API.

3.2 In the left-side navigation pane of the API management page, click Monitoring. In the upper-right corner of the page that appears, click Configure Alert Rules to go to the Cloud Monitor console.

3.3 On the page that appears, click Create Alert Rule. In the Create Alert Rule panel, set Resource Range to APIDimensions. In the API drop-down list, select one or more IDs of the APIs with which you want to associate the alert rule.

4. Associate an alert rule with an API group

4.1 To apply the same alert rule to all APIs in an API group, perform the following operations: In the left-side navigation pane, choose OpenAPI > API Groups. On the API Groups page, find the API group with which you want to associate the alert rule and click the name of the API group. In the upper-right corner of the Group Details page, click Turn on cloud monitoring.

4.2 The first time you activate CloudMonitor for an API group, a dialog box that prompts you to create a service-linked role for API Gateway appears. For more information, see AliyunServiceRoleForApiGatewayMonitoring service-linked role.

4.3 Click Confirm. The message that indicates CloudMonitor is activated for the selected API group appears. The message contains the name of the CloudMonitor application group. The application group is created by API Gateway in the CloudMonitor console after you grant the relevant permissions to API Gateway. The application group corresponds to the current API group. The name of the application group is in the following format: APIGATEWAY_${region}_${groupId}. The ${region} parameter specifies the region where the API group resides. The ${groupId} parameter specifies the ID of the API group.

4.4 After CloudMonitor is activated, click Go to CloudMonitor for Configuration in the upper-right corner of the Group Details page. On the page that appears, add the API group to the Associated Cloud Services section to apply the alert rule of the application group to the API group.

5. Associate an alert rule with all APIs

The operations that you perform to associate an alert rule with all APIs are similar to the operations described in "Section 3" of this topic. However, you must set Resource Range to All Resources. After the alert rule is configured for all APIs, the same alert rule takes effect for all APIs in API Gateway in all regions within your Alibaba Cloud account. In this case, you cannot configure an alert rule that is specific to an API. This method is applicable to scenarios in which you want to manage only a small number of APIs.

6. Alert rules supported by API Gateway

API Gateway monitors APIs from various dimensions. You can configure alert rules based on the following dimensions:

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

  • Total 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 from API Gateway within a specific period.

  • HTTP status code: the status codes that are returned by API Gateway. The following HTTP status codes are supported:

-HTTP 2XX status code: The API request is successful. Note: A successful request does not indicate that the service is successful.

-HTTP 4XX status code: An error occurs on the client, such as a parameter error.

-HTTP 5XX status code: An error occurs on a backend service. API providers must closely monitor such errors.

7. Usage notes

  • If your API groups reside in the classic network, we recommend that you use alert rules that are marked with Old. If your API groups reside in a virtual private cloud (VPC), we recommend that you use alert rules that are not marked with Old.

  • You can configure an alert rule based on the environment in which your API is published. If an alert rule configured for an API that is published in a VPC does not take effect, we recommend that you perform the following operations: Log on to the API Gateway console, find the API, and then click the API name to go to the API details page. In the left-side navigation pane, click Monitoring. On the Monitoring Data page, check whether you can query the monitoring data of the API by environment. If you cannot query the monitoring data by environment, submit a ticket to update the version of your API Gateway instance.