將Apache日誌採集到Log Service後,可以添加儀錶盤,對PV、UV、訪問地區分布、錯誤請求、用戶端類型等維度進行分析,評估網站訪問情況。
前提條件
已完成Apache日誌的Logtail採集配置。Logtail採集配置的步驟請參見採集主機文本日誌,在操作步驟2中選擇Apache-文本日誌。
背景資訊
Apache是一款主流的網站伺服器,當您選用Apache搭建網站時,Apache日誌是營運網站的重要訊息。
Log Service支援通過資料接入嚮導一站式採集Apache日誌,並為Apache日誌建立索引和儀錶盤。Apache訪問日誌儀錶盤包括來源IP分布、請求狀態佔比、要求方法佔比、訪問PV/UV統計、流入流出流量統計、請求UA佔比、前十訪問來源、訪問前十地址和請求時間前十地址等資訊,全方位展示網站訪問情況。
操作步驟
在Project列表地區,單擊目標Project。
在控制台左側,選擇
中,單擊${logstore名稱}_Apache訪問日誌。apache_Apache訪問日誌儀錶盤包括如下圖表:
來源IP分布圖展示訪問IP地址的來源情況,所關聯的查詢分析語句如下所示:
* | select ip_to_province(remote_addr) as address, count(1) as c group by ip_to_province(remote_addr) limit 100
請求狀態佔比圖展示最近一天各HTTP狀態代碼的佔比情況,所關聯的查詢分析語句如下所示:
* | select status, count(1) as pv group by status
要求方法佔比圖展示最近一天各要求方法的佔比情況,所關聯的查詢分析語句如下所示:
* | select request_method, count(1) as pv group by request_method
訪問PV/UV統計圖展示最近一天內的PV數和UV數,所關聯的查詢分析語句如下所示:
* | 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
流入流出流量統計圖展示流量的流入和流出情況,所關聯的查詢分析語句如下所示:
* | 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
請求UA佔比圖展示最近一天各種瀏覽器的佔比情況,所關聯的查詢分析語句如下所示:
* | 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
前十訪問來源圖展示最近一天PV數最多的前十個訪問來源頁面,所關聯的查詢分析語句如下所示:
* | select http_referer, count(1) as pv group by http_referer order by pv desc limit 10
訪問前十地址展示最近一天PV數最多的前十個訪問地址,所關聯的查詢分析語句如下所示:
* | 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
請求時間前十地址圖展示最近一天請求響應延時最長的前十個地址,所關聯的查詢分析語句如下所示:
* | select request_uri as top_latency_request_uri, request_time_sec order by request_time_sec desc limit 10 10