Analyze Apache logs

更新时间:
复制 MD 格式

After you ingest Apache logs into Simple Log Service, you can add a dashboard to analyze metrics like page views (PV), unique visitors (UV), visitor geography, error requests, and client types. Use this analysis to evaluate your website's traffic and performance.

Prerequisites

Logtail must be configured to collect Apache logs. For instructions, see Collect text logs from servers. In Step 2, select Apache-Text Logs.

Background information

Apache is a leading web server. If you use Apache to host your website, its logs are vital for operations and maintenance.

Simple Log Service provides a data import wizard for ingesting Apache logs. The service automatically creates an index and an out-of-the-box dashboard for your log data. This dashboard visualizes website traffic with charts such as:

Procedure

  1. Log on to the Simple Log Service console.

  2. In the Projects section, click the one you want.

    image

  3. In the left-side navigation pane, choose Dashboard > Dashboards, and click ${Logstore name}_Apache access log.

    The apache_Apache access log dashboard includes the following charts:

    • The Distribution of IP Addresses chart: Shows the geographic sources of visitor IP addresses. The following query is used for this chart:

      * | select ip_to_province(remote_addr) as address, count(1) as c group by ip_to_province(remote_addr) limit 100
    • The HTTP Status Codes chart: Shows the percentage of each HTTP status code from the last 24 hours. The following query is used for this chart:

      * | select status, count(1) as pv group by status

      请求状态占比

    • The Request Methods chart: Shows the percentage of each request method used in the last 24 hours. The following query is used for this chart:

      * | select request_method, count(1) as pv group by request_method

      请求方法占比

    • The PV and UV Statistics chart: Shows the number of PVs and UVs over the last 24 hours. The following query is used for this chart:

      * | select date_format(date_trunc('hour', __time__), '%m-%d %H:%i')  as time, count(1) as pv, approx_distinct(remote_addr) as uv group by date_format(date_trunc('hour', __time__), '%m-%d %H:%i') order by time limit 1000

      PV/UV统计

    • The Inbound and Outbound Traffic chart: Shows the amount of incoming and outgoing traffic. The following query is used for this chart:

      * | select date_format(date_trunc('hour', __time__), '%m-%d %H:%i') as time, sum(bytes_sent) as net_out, sum(bytes_received) as net_in group by time order by time limit 10000

      出入流量统计

    • The User Agents chart: Shows the distribution of browsers used to access your site in the last 24 hours. The following query is used for this chart:

      * | select case when http_user_agent like '%Chrome%' then 'Chrome' when http_user_agent like '%Firefox%' then 'Firefox' when http_user_agent like '%Safari%' then 'Safari' else 'unKnown' end as http_user_agent, count(1) as pv group by case when http_user_agent like '%Chrome%' then 'Chrome' when http_user_agent like '%Firefox%' then 'Firefox' when http_user_agent like '%Safari%' then 'Safari' else 'unKnown' end   order by pv desc limit 10

      请求UA占比

    • The Top 10 Referrers chart: Shows the top 10 referrer pages that generated the most PVs in the last 24 hours. The following query is used for this chart:

      * | select  http_referer, count(1) as pv group by http_referer order by pv desc limit 10

      前十访问来源

    • The Top 10 URIs by Number of Requests chart: Shows the 10 most frequently requested URIs (by PV count) in the last 24 hours. The following query is used for this chart:

      * | select split_part(request_uri,'?',1) as path,  count(1) as pv group by split_part(request_uri,'?',1) order by pv desc limit 10
    • The Top 10 URIs by Request Latency chart: Shows the 10 URIs with the longest response times (highest latency) in the last 24 hours. The following query is used for this chart:

      * | select request_uri as top_latency_request_uri,
                  request_time_sec 
                  order by request_time_sec desc limit 10