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

Before you configure access logging, make sure that:
  • A layer-7 listener is added.
  • Log Service is activated.
To configure access logging, follow these steps:
  1. Log on to the SLB console.
  2. In the left-side navigation pane, choose Logs > Access Logs.
  3. Select a region.
  4. 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.
  5. On the Access Logs page, find the target SLB instance and click Configure Logging.
  6. 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:

  1. 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.
  2. Click the target log field to view detailed information.
  3. 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.

  1. On the Log Service console, click the project link of the SLB instance.
  2. In the left-side navigation pane, click Search/Analytics - Query > Dashboard.
  3. Click the link of the SLB access log.
  4. 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 second.

    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.