Overview
API Gateway records the client access logs, which can help you better understand client requests, troubleshoot issues, and analyze user behaviors.
API Gateway provides a basic log dashboard in the console, where you can directly view and search for logs. It also allows you to ship logs to CLS for multidimensional statistical analysis. Directions
Step 1. Create a logset and log topic
To configure access logs in CLS, you need to first create a logset and log topic.
You can directly proceed to step 2 if you have already created a logset and log topic. 2. On the Access Logs page, select a region for the logset, and then click Create Logset in the Logset Information section.
3. In the pop-up Create Logset dialog box, set the retention period and click Save.
Note:
You can only create a single logset named "apigw_logset" in each region.
4. Click Create Log Topic in the Log Topic section of the Access Logs page.
5. In the pop-up window, select a dedicated API Gateway instance to add to the list on the right, and then click Save.
Note:
API Gateway logs are shipped at the instance level. Only dedicated instances can ship logs to CLS, while shared instances can't.
In the Operation column on the right of the log topic list, you can click Manage to edit the added dedicated API Gateway instance.
Each API Gateway instance can be added to only one log topic.
Multiple log topics can be created in a logset. You can store logs of different dedicated API Gateway instances in different log topics.
6. (Optional) To disable logging, just click Disable.
Step 2. View access logs
Without any manual configurations, API Gateway has been automatically configured with index search by access log variable. You can directly query access logs through search and analysis.
2. Select a log topic, and click Search in the operation column to redirect to the Search Analysis page in the CLS console. 3. On the Search Analysis page, enter the search syntax in the input box, select a time range, and then click Search Analysis to search for access logs reported by API Gateway to CLS.
A shipped service log is in the following format:
log_format
'[$app_id][$env_name][$service_id][$http_host][$api_id][$uri][$scheme][rsp_st:$status][ups_st:$upstream_status]'
'[cip:$remote_addr][uip:$upstream_addr][vip:$server_addr][rsp_len:$bytes_sent][req_len:$request_length]'
'[req_t:$request_time][ups_rsp_t:$upstream_response_time][ups_conn_t:$upstream_connect_time][ups_head_t:$upstream_header_time]'
'[err_msg:$err_msg][tcp_rtt:$tcpinfo_rtt][$pid][$time_local][req_id:$request_id]';
The parameters are as detailed below:
|
| |
| |
| |
| |
| |
| |
| |
| Request response status code. |
| Backend business server response status code (if the request is passed through to the backend, this variable will not be empty. If the request is blocked in API Gateway, this variable will be displayed as - ). |
| |
| Backend business service (upstream) IP. |
| VIP requested to be accessed. |
| |
| |
| Total request response time. |
| Total backend response time (time between connection establishment by API Gateway and backend response receipt). |
| Time when the backend business server is successfully connected to. |
| Time when the backend response header arrives. |
| |
| Client TCP connection information. RTT (Round Trip Time) consists of three parts: link propagation delay, end system processing delay, and queuing delay in router cache. |
| |
| |
| |
Notes
API Gateway logs are shipped at the instance level. Only dedicated instances can ship logs to CLS, while shared instances can't.
Shipping API Gateway access logs to CLS is now free of charge. You only need to pay for the CLS service.
Was this page helpful?