Help Center/ Web Application Firewall/ Best Practices/ Using LTS to Analyze WAF Logs/ Using LTS to Quickly Analyze the Average Latency and P50, P90, and P99 Latencies and Configuring Alarm Rules
Updated on 2026-10-14 GMT+08:00

Using LTS to Quickly Analyze the Average Latency and P50, P90, and P99 Latencies and Configuring Alarm Rules

Application Scenarios

After connecting your services to WAF, you can transfer WAF access logs to Log Tank Service (LTS). Using LTS SQL analysis capabilities, you can collect statistics on WAF back-to-origin request latencies, including the average latency and P50, P90, and P99 latencies. This allows you to quantify service access latency.

You can configure SQL statistical alarm rules based on latency metrics. When the service access latency goes abnormal, the system will promptly send an alarm notification, helping you identify risks such as slow requests, high API response time, and potential timeouts. The data can also help you troubleshoot issues such as service performance degradation, 504 timeout errors, and connection interruptions after your website is connected to WAF.

Resource and Cost Planning

Table 1 Resources and costs

Resource

Description

Monthly Fee

Log Tank Service (LTS)

  • Billing mode: pay-per-use
  • New log volume: 10 GB/day
  • Log retention period: 7 days

For details about billing rules, see Billing Description.

Simple Message Notification (SMN)

SMN is billed based on downstream Internet traffic and notification messages.

The fee composition in different scenarios is as follows:

  • SMS: number of SMS notifications
  • Email: Email notifications + Downstream Internet traffic
  • HTTP or HTTPS: HTTP or HTTPS notifications + Downstream Internet traffic

For details about billing rules, see Billing Description.

Web Application Firewall (WAF)

Cloud mode - standard edition:
  • Billing mode: Yearly/Monthly
  • Number of domain names that can be protected: 10
  • QPS quota: 2,000 QPS
  • Maximum bandwidth:
    • Origin servers deployed on Huawei Cloud: 100 Mbit/s
    • Origin servers deployed outside Huawei Cloud: 30 Mbit/s

For details about pricing rules, see Billing Description.

Step 1: Buy the Standard Edition Cloud WAF

The following describes how to buy the standard edition cloud WAF.

  1. Log in to the WAF console.
  2. In the upper right corner of the page, click Buy WAF. On the purchase page displayed, select Cloud Mode for WAF Mode.

    • Region: Select the region nearest to your services WAF will protect.
    • Edition: Select Standard.
    • Expansion Package and Required Duration: Set them based on site requirements.

  3. Confirm the product details and click Buy Now in the lower right corner of the page.
  4. Check the order details and read the WAF Disclaimer. Then, select the box and click Pay Now.
  5. On the payment page, select a payment method and pay for your order.

    After the order is paid, click Access Console to go to the Dashboard page. Hover over the Edition Management area to view the purchased instance edition and its specifications.

Step 2: Add Website Information to WAF

The following example shows how to add a website to WAF in cloud CNAME access mode.

  1. In the navigation pane on the left, choose Access Management.

    Before adding a website to WAF, you can click Usage Guide in the upper right corner of the page to learn about the access process.

  2. On the Access Management page, click the Cloud CNAME tab and click Add Website.

    If only one access mode is enabled, click Add Website.

  3. Configure website information as prompted.

    Figure 1 Configuring basic information
    Table 2 Key parameters

    Parameter

    Description

    Example Value

    Domain Name

    Domain name you want to add to WAF for protection.

    • The domain name has an ICP license.
    • You can enter a single domain name (for example, top-level domain name example.com or level-2 domain name www.example.com) or a wildcard domain name (*.example.com).

    www.example.com

    Protected Port

    The port over which the website traffic goes

    Standard ports

    Server Configuration

    Web server address settings. You need to configure the client protocol, server protocol, server weights, server address, and server port.

    • Client Protocol: protocol used by a client to access a server. The options are HTTP and HTTPS.
    • Server Protocol: protocol used by WAF to forward client requests. The options are HTTP and HTTPS.
    • Server Address: public IP address (generally corresponding to the A record of the domain name configured on the DNS) or domain name (generally corresponding to the CNAME record of the domain name configured on the DNS) of the web server that a client accesses.
    • Server Port: service port over which the WAF instance forwards client requests to the origin server.
    • Weight: Requests are distributed across backend origin servers based on the load balancing algorithm you select and the weight you assign to each server.

    Client Protocol: HTTP

    Server Protocol: HTTP

    Server Address: IPv4 XXX.XXX.1.1

    Server Port: 80

    IP Tag

    After a website is connected to WAF, Use Layer-7 Proxy is set to Yes by default. In this scenario, WAF is unable to directly obtain the real IP address of the client. This makes IP address-based protection rules invalid. You can select an IP tag to specify how WAF identifies client IP addresses. This enables WAF to obtain real client IP addresses.
    • $remote_sockaddr: If there is no other proxy in front of WAF, the packet contains the TCP Option Address (TOA), and you do not want WAF to use the TOA as the client IP address, select this option. With this tag configured, WAF uses the Layer 3 source IP address of the packet as the real client IP address.
    • $remote_addr: If there is a layer-4 proxy in front of WAF, WAF uses the TCP connection IP address as the real client IP address.
    • x-forwarded-for: If there is a layer-7 proxy in front of WAF, WAF uses the first IP address in the X-Forwarded-For (XFF) header as the real client IP address.
    • Custom: If there is a layer-7 proxy in front of WAF, WAF preferentially obtains the real client IP address from the configured field. If multiple fields are configured, WAF reads the real client IP address from left to right.

      If WAF does not obtain the real client IP address from the custom field, it reads the CDN-Src-Ip, X-Real-Ip, X-Forwarded-For, and $remote_addr fields in sequence to obtain the real client IP address.

    x-forwarded-for

  4. Click Next and complete the basic information about the website to be protected. Perform the following operations as prompted on the Add Website page:

    Figure 2 Domain name added to WAF
    1. Whitelist back-to-source IP addresses.
    2. Test WAF.

    After the preceding steps are complete, you can check the Access Status of the added domain name in the domain name list. The Access Status of the domain name is Inaccessible at first. You need to modify the DNS record.

Step 3: Enable LTS for Protection Logs

  1. Log in to the WAF console.
  2. Click in the upper left corner and select a region or project.
  3. (Optional) If you have enabled the enterprise project function, in the upper part of the navigation pane on the left, select your enterprise project from the Filter by enterprise project drop-down list. Then, WAF will display the related security data in the enterprise project on the page.
  4. In the navigation pane on the left, choose Security Operations > Events.
  5. Click Connect to LTS on the Log Settings tab if needed.

    Table 3 LTS configuration parameters

    Parameter

    Description

    Example Value

    Log Types

    Select the log types you want to transfer to LTS. You can transfer WAF access logs and WAF attack logs.

    Attack logs and access logs are in different formats. If you select both log types, you need to configure two different log streams.

    WAF access logs and WAF attack logs

    Log Group

    Select the log group for log transfer. You can also click Create Log Group to create a log group.

    A log group is the basic unit for LTS to manage logs. It comprises log streams and categorizes them. A log group does not store any log data. It only helps with log stream management. You can create up to 100 log groups for each account. For more details, see Managing Log Groups.

    lts-group-waf

    WAF Access Log Stream

    If you select WAF access logs for Log Types, you need to configure a WAF access log stream. You can also click Create Log Stream to create a WAF access log stream. This stream logs key information about each HTTP access, including the access time, client IP address, and requested resource URL.

    lts-topic-waf-access

    WAF Attack Log Stream

    If you select WAF attack logs for Log Types, you need to configure a WAF attack log stream. You can also click Create Log Stream to create a WAF attack log stream. This stream logs key information about each attack, including the attack type, protective action, and attack source IP address.

    lts-topic-waf-attack

    The configuration takes about 10 minutes to take effect. After the configuration takes effect, LTS is billed by traffic. For details about LTS pricing, see LTS Pricing Details.

  6. Check or analyze logs.

    After WAF is connected to LTS, log groups (① in Figure 3) and log streams (② in Figure 3) created for attack and access logs will be automatically displayed on the Log Settings tab. You can click WAF access log stream or WAF attack log stream to check, search, or analyze WAF logs. For more details, see Searching and Analyzing Logs.

    Figure 3 Log Settings

  7. After selecting a log stream, on the Log Search tab (③ in Figure 3), choose > Download Logs (④ in Figure 3) to download the reported logs in the log stream.

    • Frontend download: You can directly save log query results to a local PC. Download records will not appear in your log download history. Each time you can download up to 5,000 log records. You can download logs in .csv or .txt format.
    • Offline backend download: You can download log files to a temporary OBS bucket via a backend task. Your browser must have public network access to download these files from your log download history. Each time you can download up to 20 million log records. You can download logs in .csv, .txt, or .json format.

    You can also download log files through an OBS transfer task. For details, see Transferring Logs to OBS.

Step 4: Quickly Analyze the Average Latency and P50, P90, and P99 Latencies

  1. Log in to the LTS console.
  2. In the log group list, expand the WAF log group and select the access log stream, for example, lts-topic-waf-access.
  3. On the log stream details page, click in the upper right corner. On the page displayed, click the Cloud Structured Parsing tab.
  4. Select JSON for log structuring. Then, click Select from existing events and select a log in the dialog box displayed on the right.
  5. Click Intelligent Extraction to find the fields you want to analyze quickly. Enable these fields in the Quick Analysis column. After this, you can collect and analyze periodic logs.

    Figure 4 Log extraction field

  6. Find the category field, click in the Alias column, change the field name, and click to save the settings.

    There is already a built-in category field in the system so you need to change the alias name of the category field, or your settings cannot be saved.

  7. In the lower right corner of the list, click Save. LTS quickly analyzes and collects statistics on logs in the specified period.
  8. In the navigation pane, choose Visualization. On the right pane, select a log query time range, enter an SQL statement in the search box, and click Query.

    You can group logs by rule and URI. Enter the following SQL statement in the search box to query logs of a specified rule:

    select TIME_CEIL(__time,'PT300S') as _time_, avg(request_time) * 1000 as "Average", APPROX_QUANTILE_DS("request_time", 0.50)*1000 as "P50", APPROX_QUANTILE_DS("request_time", 0.90)*1000 as "P90" ,APPROX_QUANTILE_DS("request_time", 0.99)*1000 as 'P99' where response_code = '200' group by _time_

    For details about the SQL query syntax, see Using SQL Analysis Syntax.

    The Visualization module is available only to whitelisted users in CN North-Beijing4.

Step 5: Configure Alarm Rules

  1. Log in to the LTS console.
  2. In the navigation pane on the left, choose Log Alarms > Alarm Rules.
  3. Click Create. In the dialog box displayed on the right, specify related parameters. Table 4 describes the parameters. Figure 5 shows an example.

    Figure 5 Configuring alarm rules (1)

    Table 4 Parameter description

    Parameter

    Description

    Example

    Rule Name

    Name of the custom rule.

    WAF alarms

    Statistical Type

    Select By SQL.

    By SQL

    Charts

    Click Configure from Scratch.

    • Specify Log Group Name and Log Stream Name.
    • Query Time Range: Time range for log statistics
    • Query Statement: SQL statement configured in 8, for example, select TIME_CEIL(__time,'PT300S') as _time_, avg(request_time) * 1000 as "Average", APPROX_QUANTILE_DS("request_time", 0.50)*1000 as "P50", APPROX_QUANTILE_DS("request_time", 0.90)*1000 as "P90" ,APPROX_QUANTILE_DS("request_time", 0.99)*1000 as 'P99' where response_code = '200' group by _time_

    -

    Query Frequency

    Frequency that triggers alarms. Select Custom Interval and set it to 5 minutes.

    Custom interval

    5

    minutes

    Conditional Expression

    Alarm threshold.

    cnt>5

    Alarm Severity

    Select an alarm severity based on the urgency of the rule. The options are Critical, Major, Minor, and Info.

    Major

    Send Notification

    Select Yes.

    Yes

    SMN Topic

    Select a topic from the drop-down list or create a topic.

    If there are no topics, click View Topic and perform the following steps to create a topic:

    • Create a topic. For details, see Creating a Topic.
    • Add one or more subscriptions to the topic. You will need to provide a phone number, email address, function, platform application endpoint, DMS endpoint, or HTTP/HTTPS endpoint for receiving alarm notifications. For details, see Adding a Subscription.
    • Confirm the subscription. After the subscription is added, confirm the subscription.

    For details about topics and subscriptions, see the Simple Message Notification User Guide.

    -

    Time Zone/Language

    You can modify the language and time zone for receiving messages.

    -

    Message Templates

    Select an existing template from the drop-down list box or click Create Message Template and create a template.

    sql_template

  4. Confirm all parameters and click OK. The alarm rule is configured. When the alarm rule is triggered, you will receive an alarm email or SMS message.