When the response is delayed, you can view the response time of the SLB instance in the dashboard provided by Log Service. By viewing the response time, you can locate the unhealthy backend server.
This tutorial introduces how to use access logs to rapidly locate an unhealthy backend server.
Task 1: Configure access logs
- A layer-7 listener is added.
- Log Service is activated.
- Log on to the SLB console.
- In the left-side navigation pane, choose .
- Select a region.
- Click Authorize, and then click Confirm Authorization Policy to authorize SLB to write logs to Log Service.
If you are a RAM user, you must obtain permissions from the corresponding Alibaba Cloud account. For more information, see Authorize a RAM user to use access logs.Note This step is only required when you configure access logging for the first time.
- On the Access Logs page, find the target SLB instance and click Configure Logging.
- Select a LogProject and LogStore and then click OK.
If there is no available LogStore, click Log Service console to create log projects.Note Make sure that the name of the LogProject is globally unique and the region of the LogProject is the same as that of the SLB instance.
Task 2: Search for access logs
To search for access logs, follow these steps:
- Go to the log search page. You can navigate to the search page from the SLB console
or the Log Service console:
- From the SLB console:
On the Access Logs page, click View Logs.
- From the Log Service console:
On the Logstores page, click Search of the target Logstore.
- From the SLB console:
- Click the target log field to view detailed information.
- Enter an SQL statement to query access logs.
For example, enter the following SQL statement to query the Top20 clients, which is used for analyzing the request source to assist business decision-making.
* | select ip_to_province(client_ip) as client_ip_province, count(*) as pv group by client_ip_province order by pv desc limit 50
Task 3: Locate the unhealthy backend server
You can locate the unhealthy backend server by checking the dashboard of Log Service.
- On the Log Service console, click the project link of the SLB instance.
- In the left-side navigation pane, click
- Click the link of the SLB access log.
- In the dashboard, view the value in the top upstream response time tab. You can select to display the Average upstream response time (s) in descending order to check if the response time of a backend server surpasses 1
If the repsonse tie does surpass 1 second, run the ssh command to log on to the backend server. Check whether the CPU usage is high and handle the high loads.