Updated on 2026-11-02 GMT+08:00

Example of Using Bucket Log Analysis

This section uses the querying of hot objects (the top 10 objects by request count) as an example to describe how to configure and analyze logs, and provides log query statements for typical scenarios.

Log analysis is available only in certain regions (for example, CN East 2). Refer to the console for the actual support status.

Resource and Cost Planning

Table 1 Resource planning

Region

Resources

Resource Name

Resource Description

Quantity

Billing

CN East2

(The OBS bucket, log group, and log stream must be in the same region.)

OBS bucket

lts-bestpractice

The bucket configured for log analysis.

1

You are billed for the storage used by objects uploaded to the bucket. For details, see Storage Space.

Log group

lts-group-bestpractice

LTS log group for log management.

1

  • LTS dynamically collects and stores log data. You are billed for log storage.
  • Uploading log data to LTS incurs log read/write traffic fees.
  • Log search and analysis incur charges for index traffic - standard log streams.

For details, see LTS Billing.

Log stream

log-streams-bestpractice

LTS log stream for log storage and structured query management.

1

Prerequisites

You have a bucket that requires log analysis, and the bucket contains objects. For detailed operations, see Creating a Bucket and Uploading Objects.

Operation Process

Figure 1 Process of configuring log analysis

Figure 1 shows the process of using LTS to analyze OBS logs in real time.

Procedure

The following procedure describes how to use LTS to analyze logs in real time.

Step 1: Enable Log Analysis and Bind a Log Group and Log Stream

  1. In the navigation pane of OBS Console, choose Buckets.
  2. In the bucket list, click the desired bucket. The Objects page is displayed.
  3. In the navigation pane, choose Log Management > Log Analysis. The Log Analysis page is displayed.
  4. Click Configure Log Ingestion in the upper right corner of the page.

  5. In the Configure Log Ingestion to LTS dialog box, set related parameters.

    Figure 2 Configuring log ingestion to LTS

    Table 2 Parameters for log ingestion to LTS

    Parameter

    Example Value

    Description

    Ingest Logs to LTS

    Enabled

    Once this function is enabled, the system stores logs generated by the bucket to LTS for log search and analysis.

    Log Types

    OBS access logs

    The cloud service integrated with LTS.

    The OBS access logs option is selected by default and cannot be modified. To cancel this selection, deselect the Ingest Logs to LTS check box above.

    Project

    CN East2

    Select the region where the bucket is located.

    Log Group

    lts-group-bestpractice

    Select the log group you created in LTS. If no log group is available, click Create Log Group to create one. For parameter details, see Creating a Log Group.

    Log Stream

    log-streams-bestpractice

    Select the log stream you created in a log group. If no log stream is available, click Create Log Stream to create one. For parameter details, see Creating a Log Stream.

  6. Click OK.

    After log analysis is configured, you can view the bucket's operation logs in the lower part of the Log Analysis page about 10 minutes later.

Step 2: Configure Cloud Structuring Parsing for the Log Stream

  1. Click Log Settings in the upper right corner of the Log Details page. The log stream settings page is displayed.

  2. Click the Cloud Structuring Parsing tab.
  3. Configure the parameters as described in the following table. Keep the default settings for other parameters.

    For more information, see Setting Cloud Structuring Parsing.

    Table 3 Cloud structuring parsing parameters

    Parameter

    Example Value

    Description

    Log structuring method

    JSON

    Select a log structuring method based on the log content.

    In this example, select JSON.

    Step 1 Select a sample log event.

    See the sample log.

    Select a sample log to serve as the input for Intelligent Extract in the next step, where log fields will be extracted.

    Step 2 Extract fields.

    Intelligent Extract

    Click Intelligent Extract to automatically extract fields from the sample log.

    • Sample log
      {"referer":"https://console.huaweicloud.com/obs/gray?locale=zh-cn&region=cn-north-4","content_length_in":0,"vpc_id":"-","owner_id":"29e******","bucket_storage_type":"STANDARD","http_method":"HEAD","response_body_length":0,"source_identity":"-","bucket_location":"cn-north-4","host":"lts-bestpractice.obs.cn-north-4.huaweicloud.com","client_ip":"100.00.0.000","server_cost_time":6,"vpc_addr":"-","sign_type":"v2","user_agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/150.0.0.0 Safari/537.36 Edg/150.0.0.0","object_size":"0","object_storage_class":"STANDARD","object_target_storage_class":"-","ssl_protocol":"TLSv1.2","http_type":"https","http_range":"-","request_uri":"/obj1","bucket":"dsa","principle_urn":"-","enterprise_project_id":"0","request_length":2756,"content_length_out":0,"access_key":"HSTA***","logging":"FALSE","http_status":200,"response_time":6,"error_code":"-","time":"25/Jul/2026:16:43:00","request_id":"42f75cef266754de18c8d4b9abd2ed3a","operation":"HEAD.OBJECT","requester_id":"5cc796b35e824f30a6a63982f360fc47","object":"obj1"}

  4. Click Save.

Step 3: Configure Log Stream Indexes

  1. Click Log Settings in the upper right corner of the Log Details page. The log stream settings page is displayed.
  2. Click the Index Settings tab.
  3. Click Auto Configure under Index Fields.

    Field indexing allows you to add fields extracted from Step 2: Configure Cloud Structuring Parsing for the Log Stream to perform statistics and analysis on log data. If you change any field names on the Cloud Structuring Parsing page, you must re-add the field indexes.

    For more information, see Configuring LTS Log Indexing.

  4. Click OK.

Step 4: Analyze Logs

  1. Click the Log Search tab and enter a SQL statement in the search box to query and analyze OBS logs.

    For example, to query the top 10 objects by number of requests, enter the following SQL statement:

    The fields in the example are explained as follows:

    • bucket: the bucket name. Replace it with your own bucket name.
    • LIMIT: the maximum number of returned results. Configure it as required. For example, set it to 10 to query top 10 objects by request count.
    * | SELECT
        url_decode(object) AS object_path,
        COUNT(*) AS request_count
    FROM log
    WHERE
        bucket = 'lts-bestpractice'
        AND object IS NOT NULL
        AND object != ''
        AND object != '-'
    GROUP BY object_path
    ORDER BY request_count DESC
    LIMIT 10

  2. Click the Charts tab to view the log analysis result.

    The log analysis result shown in the following figure lists the top 10 objects by request count.

More SQL Query Examples for Log Analysis

Below are SQL query statements for typical scenarios. The common fields used in these examples are described as follows and can be adjusted as needed:

  • bucket: bucket name. Replace it with your own bucket name.
  • LIMIT: maximum number of returned query results. Configure it as required. For example, set it to 10 to query top 10 objects by request count.
  • http_method: request method. Set it to PUT or POST to query inbound traffic, or set it to GET to query outbound traffic.
  • date_parse: log time. Set the start time and end time for the log query as required.