大資料技術學習筆記之網站流量日誌分析專案:網站業務與企業架構2
阿新 • • 發佈:2018-12-07
一、回顧
-》flume使用遇到的錯誤
-》少jar包
-》卡住不動:agent檔案不對
-》環境變數:hdfs、hive
-》Flume三大元件
-》source:負責採集資料來源,將資料來源變成資料流,封裝在event當中,將封裝好的資料流傳送給channel
-》channel:負責將source傳送過來的資料進行臨時儲存
-》sink:負責從channel取資料流,將資料流傳送到目標地
-》flume執行:定義一個配置檔案:agent(source、channel、sink)
bin/flume-ng agent
--conf flume_conf_dir
--name agent_name
--conf-file agent_file_path -Dflume.root.logger=INFO,console
-》flume常用的元件型別
-》source:
-》exec:用於執行一條Linux命令,通過命令讀取資料流
一般都使用tail -F 來動態讀取某一個檔案的變化
-》spooling 目錄檔案 directory:用於監控一個目錄,動態讀取目錄中的檔案
-》taildir:用於動態監控多個檔案,並且動態監控每個檔案的變化
-》channel:
-》file:將資料流暫存在檔案中,相對慢,安全性高,適合資料量大
-》mem:將資料快取在記憶體中,相對快,安全性低,適合小資料量
-》sink:
hdfs:用於將資料儲存到hdfs、檔案大小、分割槽.取名
hive:將資料寫入hive表
-》要求必須開啟metastore server服務
hive.metastore.uris=thrift://hostname:9083
bin/hive --service metastore
client-》hiveserver2-》metastore server
-》hive的表必須是一張桶表
-》要求hive中檔案格式必須為orc型別
-》在工作中,一般不使用hive sink,使用hdfs sink,手動新增
hbase:將資料寫入hbase
-》HBaseSink:實時將資料寫入hbase
SimpleHbaseEventSerializer:將一個event中所有的資料作為一列
RegexHbaseEventSerializer:通過正則匹配每一列
-》AsyncHBaseSink:非同步將資料寫入hbase
-》不寫securety hbase:預設是SimpleAsyncHbaseEventSerializerr
二、Flume的企業架構
-1》taildir source:監控多個檔案
a1.sources.s1.type = TAILDIR
a1.sources.s1.positionFile = /opt/cdh-5.7.6/flume-1.6.0-cdh5.7.6-bin/position/taildir_position.json //作用是儲存是否讀取過還是沒讀
a1.sources.s1.filegroups = f1 f2 //監控兩個檔案f1 f2
a1.sources.s1.filegroups.f1 = /opt/datas/flume/taildir/hadoop.txt
a1.sources.s1.headers.f1.headerKey1 = value1
a1.sources.s1.filegroups.f2 = /opt/datas/flume/taildir/dir/.*
a1.sources.s1.headers.f2.headerKey1 = value2
-》多sink:多個目標地
-》應用場景:用於採集到的資料傳送給多個目標地
-》實現:在agent中定義多個channel,多個sink即可
注意:一個sink要對應一個channel
a1.sources = s1
a1.channels = c1 c2
a1.sinks = k1 k2
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100
a1.channels.c2.type = memory
a1.channels.c2.capacity = 1000
a1.channels.c2.transactionCapacity = 100
a1.sinks.k1.type = hdfs
///
a1.sinks.k2.type = hdfs
///
a1.sources.s1.channels = c1 c2
a1.sinks.k1.channel = c1
a1.sinks.k2.channel = c2
-》flume collector(收集所有的flumes的資料統一發送給目標地)
-》flume agent:用於採集資料,一般有多個agent在多臺機器上
-》flume collector:用於收集所有flume agent的資料,統一發送給hdfs
-》應用場景:為了解決高併發寫入hdfs,引起磁碟及網路負載的問題
-》一般使用固定的網路型的sink和source配對:avro sink / avro source
flume agent:
source:exec/spooling dir/taildir
channel:mem/file
sink:avro sink
//1 type – The component type name, needs to be avro.
//2 hostname – The hostname or IP address to bind to.
決定了你要傳送給誰,這裡配的是collector的地址
//3 port – The port # to listen on.
與collector監聽一致的埠號:4545
flume collector:
source : avro source
//1 type – The component type name, needs to be avro
//2 bind – hostname or IP address to listen on
自己的ip或者主機名
//3 port – Port # to bind to
監聽的埠號
channel:mem
sink:hdfs
-》啟動順序:
-》先啟動collector
-》後啟動agent
三、三大高階元件
-》flume攔截器:Flume Interceptors
封裝event的頭部,用於對資料進行過濾或者包裝的
-》Timestamp Interceptor:時間戳攔截器
-》在所有event的頭部新增一個keyvalue
key是timestamp
value就是具體的timestamp的值
-》一般用於hdfs分割槽時
-》Host Interceptor:主機名攔截器
-》在所有event的頭部新增一個keyvalue
key是host
value就是該event所在的機器主機名
-》Static Interceptor:自定義keyvalue(根據需要自己定義)
a1.sources.s1.interceptors = i1
a1.sources.s1.interceptors.i1.type = static
a1.sources.s1.interceptors.i1.key = datacenter
a1.sources.s1.interceptors.i1.value = NEW_YORK
-》Regex Filtering Interceptor:正則匹配攔截器
-》自定義正則表示式
-》如果你的event資料符合該正則就會被採集
a1.sources.r1.interceptors.i1.regex = (\\d):(\\d):(\\d)
-》Regex Extractor Interceptor
-》在頭部自定義一個正則表示式
-》結合timestamp攔截器和Regex Filtering Interceptor實現對於資料的封裝和過濾(只採集擁有花括號的行)
{1,2,3,4}
1,2,3
{5,6,7,8}
a1.sources.s1.interceptors = i1 i2
a1.sources.s1.interceptors.i1.type = timestamp
a1.sources.s1.interceptors.i2.type = regex_filter
a1.sources.s1.interceptors.i2.regex = (?<=\{)[^}]*(?=\})
報錯:正則表示式出錯
Source s1 has been removed due to an error during configuration
java.util.regex.PatternSyntaxException: Illegal repetition {^ *}
-》Flume Channel Selectors(不同的channel不同的值)
Replicating Channel(預設型別) Selector:預設將資料傳送給每一個channel
Multiplexing Channel Selector:根據值的不同傳送給不同的channel
a1.sources = r1
a1.channels = c1 c2 c3 c4
a1.sources.r1.selector.type = multiplexing
a1.sources.r1.selector.header = host
a1.sources.r1.selector.mapping.host1 = c1
a1.sources.r1.selector.mapping.host2 = c2 c3
a1.sources.r1.selector.default = c4
-》Flume Sink Processors
-》sinkgroup:將多個sink進行統一封裝
-》負載均衡:load_balance
-》隨機
-》輪詢
a1.sinkgroups = g1
a1.sinkgroups.g1.sinks = k1 k2
a1.sinkgroups.g1.processor.type = load_balance
-》故障轉移:failover
a1.sinkgroups = g1
a1.sinkgroups.g1.sinks = k1 k2
a1.sinkgroups.g1.processor.type = failover
a1.sinkgroups.g1.processor.priority.k1 = 5
a1.sinkgroups.g1.processor.priority.k2 = 10 //priority權重越高,先工作
四、web日誌的產生
-》流程:
-》使用者通過搜尋/直接輸入網址/通過連線廣告進入網站
-》使用者根據需求產生一系列的事件:點選、收藏、下單
-》使用者傳送請求
-》使用者的請求被反向代理伺服器進行接收轉接給後臺伺服器
-》反向代理伺服器:Nginx
-》後臺伺服器:真正接收使用者請求並且返回內容記錄日誌
-》後臺伺服器記錄使用者的請求資訊(訪問日誌)
-》使用者請求的型別
-》請求訪問的頁面
-》當前的頁面
-》使用者的基本資訊
-》後臺伺服器根據使用者的請求返回相應的結果
-》網站日誌內容
-》內容的收集
-》通過指令碼監聽使用者的行為,一旦使用者觸發,那麼就會收集相應的日誌
-》使用者id:guid
-》會員id:member_id/user_id
-》ip(國家、省份、城市)
-》時間
-》客戶端(瀏覽器+作業系統)
-》資訊的分類
系統屬性特徵:比如所採用的作業系統、瀏覽器、域名和訪問速度等。
訪問特徵:包括停留時間、點選的URL等。
來源特徵:包括網路內容資訊型別、內容分類和來訪URL等。
產品特徵:包括所訪問的產品編號、產品類別、產品顏色、產品價格、產品利潤、產品數量和特價等級等。
https://search.jd.com/Search?keyword=%E5%A4%A7%E7%B1%B3&enc=utf-8&suggest=1.his.0.0&wq=&pvid=c008748f1965447398c69635d6b024d3
五、點選流
-》使用者的訪問流程:會話
-》使用者開啟第一個網頁(主頁)
-》與網站建立連線,建立session
-》使用者不斷的訪問頁面
-》使用者關閉所有頁面,session超時
-》兩個MapReduce實現統計不同會話時長段的個數
日誌資料:
session1 ts1
session2 ts1
session1 ts2
session1 ts3
session2 ts2
-》第一個MapReduce:求每個sessionid對應的時長
session1 length1
session2 length2
-》第二個MapReduce:求不同會話時長段的個數
if(length<10 )
context.write(0-10,1)
else if (length <20)
context.write(11-20,1)
key:0-10/11-20
value: 1
-》使用者點選流的應用
-》使用者採集的資訊經過分析較為單一、所能得到的資訊價值較低
-》構建點選流可以更精確的對使用者的行為,習慣進行了解和分析
-》如何構建點選流
-》源表:
每一條記錄構建篩選出來的訪問資訊
sessionid timestamp userid ip url refere_url
-》點選流表:pageviews
sessionid1 ts1 1 url1 40
sessionid1 ts2 2 url2 20
sessionid1 ts3 3 url3 30
sessionid2 ts1 1 url1 10
sessionid2 ts2 2 url2 20
-》點選流visit表:
sessionid1 start_time stop_time pv length userid
六、流量分析
-》分析內容:
-》網站業務指標:公共業務指標
-》百度統計
-》友盟
-》易分析
-》talking data
-》模組
-》使用者分析
使用者分析:新使用者、老使用者、迴流使用者、流失使用者、總使用者
新會員、老會員、總會員、活躍會員
使用者趨勢 :按照時間維度進行趨勢分析
活躍使用者 :當前訪問使用者
使用者畫像 :根據使用者特性,分析使用者屬性
地域分佈 :基於地域維度進行統計
終端分析 :安卓、ios、移動裝置、筆記本
版本分析 :針對不同客戶端的版本進行分析
實時訪客 :實時訪問的人數
使用行為 :下訂單、收藏商品、訪問某個商品
事件分析 :訂單提交、訂單回退、新增購物車,結算
頁面分析 :哪個連線使用者點選最多,熱點圖
頁面路徑 :使用者訪問路徑
使用習慣 :使用者習慣
渠道分析 :使用者如果進入網站
渠道來源細分 :來源分析
留存分析 :使用者進來,留存多少使用者
新使用者留存 :
活躍使用者留存 :
轉化分析 :訪客轉會員
轉化漏斗:
-》分析的功能
-》優化網站,提高使用者的體驗
-》提供運營決策
-》分析模型
-》質量分析模型
-》重視流量的質量
-》多維度分析模型
-》基於多維度的組合分析
-》時間維度
-》地域維度
-》終端維度
-》網站內容及導航分析模型
-》導航
-》功能:註冊、購物車
-》詳情
-》網站的轉化及漏斗分析
-》轉化:業務層面的用於流式和迷失的結果
-》購買商品
進入網站 瀏覽商品 註冊 新增購物車 支付
1000 900 300 150 50
10% 70% 85% 95%
-》漏斗:使用者訪問層面的流式和迷失的結果
首頁 一級頁面 二級頁面 三級頁面
1000 400 200 10
60% 80% 99%
-》分析模組
-》基礎分析:pv,uv,ip,跳出率,二跳率
-》來源分析:
-》受訪分析:
-》訪客分析:
-》轉化路徑分析:
-》flume使用遇到的錯誤
-》少jar包
-》卡住不動:agent檔案不對
-》環境變數:hdfs、hive
-》Flume三大元件
-》source:負責採集資料來源,將資料來源變成資料流,封裝在event當中,將封裝好的資料流傳送給channel
-》channel:負責將source傳送過來的資料進行臨時儲存
-》sink:負責從channel取資料流,將資料流傳送到目標地
-》flume執行:定義一個配置檔案:agent(source、channel、sink)
bin/flume-ng agent
--conf flume_conf_dir
--name agent_name
--conf-file agent_file_path -Dflume.root.logger=INFO,console
-》flume常用的元件型別
-》source:
-》exec:用於執行一條Linux命令,通過命令讀取資料流
一般都使用tail -F 來動態讀取某一個檔案的變化
-》spooling 目錄檔案 directory:用於監控一個目錄,動態讀取目錄中的檔案
-》taildir:用於動態監控多個檔案,並且動態監控每個檔案的變化
-》channel:
-》file:將資料流暫存在檔案中,相對慢,安全性高,適合資料量大
-》mem:將資料快取在記憶體中,相對快,安全性低,適合小資料量
-》sink:
hdfs:用於將資料儲存到hdfs、檔案大小、分割槽.取名
hive:將資料寫入hive表
-》要求必須開啟metastore server服務
hive.metastore.uris=thrift://hostname:9083
bin/hive --service metastore
client-》hiveserver2-》metastore server
-》hive的表必須是一張桶表
-》要求hive中檔案格式必須為orc型別
-》在工作中,一般不使用hive sink,使用hdfs sink,手動新增
hbase:將資料寫入hbase
-》HBaseSink:實時將資料寫入hbase
SimpleHbaseEventSerializer:將一個event中所有的資料作為一列
RegexHbaseEventSerializer:通過正則匹配每一列
-》AsyncHBaseSink:非同步將資料寫入hbase
-》不寫securety hbase:預設是SimpleAsyncHbaseEventSerializerr
二、Flume的企業架構
-1》taildir source:監控多個檔案
a1.sources.s1.type = TAILDIR
a1.sources.s1.positionFile = /opt/cdh-5.7.6/flume-1.6.0-cdh5.7.6-bin/position/taildir_position.json //作用是儲存是否讀取過還是沒讀
a1.sources.s1.filegroups = f1 f2 //監控兩個檔案f1 f2
a1.sources.s1.filegroups.f1 = /opt/datas/flume/taildir/hadoop.txt
a1.sources.s1.headers.f1.headerKey1 = value1
a1.sources.s1.filegroups.f2 = /opt/datas/flume/taildir/dir/.*
a1.sources.s1.headers.f2.headerKey1 = value2
-》多sink:多個目標地
-》應用場景:用於採集到的資料傳送給多個目標地
-》實現:在agent中定義多個channel,多個sink即可
注意:一個sink要對應一個channel
a1.sources = s1
a1.channels = c1 c2
a1.sinks = k1 k2
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100
a1.channels.c2.type = memory
a1.channels.c2.capacity = 1000
a1.channels.c2.transactionCapacity = 100
a1.sinks.k1.type = hdfs
///
a1.sinks.k2.type = hdfs
///
a1.sources.s1.channels = c1 c2
a1.sinks.k1.channel = c1
a1.sinks.k2.channel = c2
-》flume collector(收集所有的flumes的資料統一發送給目標地)
-》flume agent:用於採集資料,一般有多個agent在多臺機器上
-》flume collector:用於收集所有flume agent的資料,統一發送給hdfs
-》應用場景:為了解決高併發寫入hdfs,引起磁碟及網路負載的問題
-》一般使用固定的網路型的sink和source配對:avro sink / avro source
flume agent:
source:exec/spooling dir/taildir
channel:mem/file
sink:avro sink
//1 type – The component type name, needs to be avro.
//2 hostname – The hostname or IP address to bind to.
決定了你要傳送給誰,這裡配的是collector的地址
//3 port – The port # to listen on.
與collector監聽一致的埠號:4545
flume collector:
source : avro source
//1 type – The component type name, needs to be avro
//2 bind – hostname or IP address to listen on
自己的ip或者主機名
//3 port – Port # to bind to
監聽的埠號
channel:mem
sink:hdfs
-》啟動順序:
-》先啟動collector
-》後啟動agent
三、三大高階元件
-》flume攔截器:Flume Interceptors
封裝event的頭部,用於對資料進行過濾或者包裝的
-》Timestamp Interceptor:時間戳攔截器
-》在所有event的頭部新增一個keyvalue
key是timestamp
value就是具體的timestamp的值
-》一般用於hdfs分割槽時
-》Host Interceptor:主機名攔截器
-》在所有event的頭部新增一個keyvalue
key是host
value就是該event所在的機器主機名
-》Static Interceptor:自定義keyvalue(根據需要自己定義)
a1.sources.s1.interceptors = i1
a1.sources.s1.interceptors.i1.type = static
a1.sources.s1.interceptors.i1.key = datacenter
a1.sources.s1.interceptors.i1.value = NEW_YORK
-》Regex Filtering Interceptor:正則匹配攔截器
-》自定義正則表示式
-》如果你的event資料符合該正則就會被採集
a1.sources.r1.interceptors.i1.regex = (\\d):(\\d):(\\d)
-》Regex Extractor Interceptor
-》在頭部自定義一個正則表示式
-》結合timestamp攔截器和Regex Filtering Interceptor實現對於資料的封裝和過濾(只採集擁有花括號的行)
{1,2,3,4}
1,2,3
{5,6,7,8}
a1.sources.s1.interceptors = i1 i2
a1.sources.s1.interceptors.i1.type = timestamp
a1.sources.s1.interceptors.i2.type = regex_filter
a1.sources.s1.interceptors.i2.regex = (?<=\{)[^}]*(?=\})
報錯:正則表示式出錯
Source s1 has been removed due to an error during configuration
java.util.regex.PatternSyntaxException: Illegal repetition {^ *}
-》Flume Channel Selectors(不同的channel不同的值)
Replicating Channel(預設型別) Selector:預設將資料傳送給每一個channel
Multiplexing Channel Selector:根據值的不同傳送給不同的channel
a1.sources = r1
a1.channels = c1 c2 c3 c4
a1.sources.r1.selector.type = multiplexing
a1.sources.r1.selector.header = host
a1.sources.r1.selector.mapping.host1 = c1
a1.sources.r1.selector.mapping.host2 = c2 c3
a1.sources.r1.selector.default = c4
-》Flume Sink Processors
-》sinkgroup:將多個sink進行統一封裝
-》負載均衡:load_balance
-》隨機
-》輪詢
a1.sinkgroups = g1
a1.sinkgroups.g1.sinks = k1 k2
a1.sinkgroups.g1.processor.type = load_balance
-》故障轉移:failover
a1.sinkgroups = g1
a1.sinkgroups.g1.sinks = k1 k2
a1.sinkgroups.g1.processor.type = failover
a1.sinkgroups.g1.processor.priority.k1 = 5
a1.sinkgroups.g1.processor.priority.k2 = 10 //priority權重越高,先工作
四、web日誌的產生
-》流程:
-》使用者通過搜尋/直接輸入網址/通過連線廣告進入網站
-》使用者根據需求產生一系列的事件:點選、收藏、下單
-》使用者傳送請求
-》使用者的請求被反向代理伺服器進行接收轉接給後臺伺服器
-》反向代理伺服器:Nginx
-》後臺伺服器:真正接收使用者請求並且返回內容記錄日誌
-》後臺伺服器記錄使用者的請求資訊(訪問日誌)
-》使用者請求的型別
-》請求訪問的頁面
-》當前的頁面
-》使用者的基本資訊
-》後臺伺服器根據使用者的請求返回相應的結果
-》網站日誌內容
-》內容的收集
-》通過指令碼監聽使用者的行為,一旦使用者觸發,那麼就會收集相應的日誌
-》使用者id:guid
-》會員id:member_id/user_id
-》ip(國家、省份、城市)
-》時間
-》客戶端(瀏覽器+作業系統)
-》資訊的分類
系統屬性特徵:比如所採用的作業系統、瀏覽器、域名和訪問速度等。
訪問特徵:包括停留時間、點選的URL等。
來源特徵:包括網路內容資訊型別、內容分類和來訪URL等。
產品特徵:包括所訪問的產品編號、產品類別、產品顏色、產品價格、產品利潤、產品數量和特價等級等。
https://search.jd.com/Search?keyword=%E5%A4%A7%E7%B1%B3&enc=utf-8&suggest=1.his.0.0&wq=&pvid=c008748f1965447398c69635d6b024d3
五、點選流
-》使用者的訪問流程:會話
-》使用者開啟第一個網頁(主頁)
-》與網站建立連線,建立session
-》使用者不斷的訪問頁面
-》使用者關閉所有頁面,session超時
-》兩個MapReduce實現統計不同會話時長段的個數
日誌資料:
session1 ts1
session2 ts1
session1 ts2
session1 ts3
session2 ts2
-》第一個MapReduce:求每個sessionid對應的時長
session1 length1
session2 length2
-》第二個MapReduce:求不同會話時長段的個數
if(length<10 )
context.write(0-10,1)
else if (length <20)
context.write(11-20,1)
key:0-10/11-20
value: 1
-》使用者點選流的應用
-》使用者採集的資訊經過分析較為單一、所能得到的資訊價值較低
-》構建點選流可以更精確的對使用者的行為,習慣進行了解和分析
-》如何構建點選流
-》源表:
每一條記錄構建篩選出來的訪問資訊
sessionid timestamp userid ip url refere_url
-》點選流表:pageviews
sessionid1 ts1 1 url1 40
sessionid1 ts2 2 url2 20
sessionid1 ts3 3 url3 30
sessionid2 ts1 1 url1 10
sessionid2 ts2 2 url2 20
-》點選流visit表:
sessionid1 start_time stop_time pv length userid
六、流量分析
-》分析內容:
-》網站業務指標:公共業務指標
-》百度統計
-》友盟
-》易分析
-》talking data
-》模組
-》使用者分析
使用者分析:新使用者、老使用者、迴流使用者、流失使用者、總使用者
新會員、老會員、總會員、活躍會員
使用者趨勢 :按照時間維度進行趨勢分析
活躍使用者 :當前訪問使用者
使用者畫像 :根據使用者特性,分析使用者屬性
地域分佈 :基於地域維度進行統計
終端分析 :安卓、ios、移動裝置、筆記本
版本分析 :針對不同客戶端的版本進行分析
實時訪客 :實時訪問的人數
使用行為 :下訂單、收藏商品、訪問某個商品
事件分析 :訂單提交、訂單回退、新增購物車,結算
頁面分析 :哪個連線使用者點選最多,熱點圖
頁面路徑 :使用者訪問路徑
使用習慣 :使用者習慣
渠道分析 :使用者如果進入網站
渠道來源細分 :來源分析
留存分析 :使用者進來,留存多少使用者
新使用者留存 :
活躍使用者留存 :
轉化分析 :訪客轉會員
轉化漏斗:
-》分析的功能
-》優化網站,提高使用者的體驗
-》提供運營決策
-》分析模型
-》質量分析模型
-》重視流量的質量
-》多維度分析模型
-》基於多維度的組合分析
-》時間維度
-》地域維度
-》終端維度
-》網站內容及導航分析模型
-》導航
-》功能:註冊、購物車
-》詳情
-》網站的轉化及漏斗分析
-》轉化:業務層面的用於流式和迷失的結果
-》購買商品
進入網站 瀏覽商品 註冊 新增購物車 支付
1000 900 300 150 50
10% 70% 85% 95%
-》漏斗:使用者訪問層面的流式和迷失的結果
首頁 一級頁面 二級頁面 三級頁面
1000 400 200 10
60% 80% 99%
-》分析模組
-》基礎分析:pv,uv,ip,跳出率,二跳率
-》來源分析:
-》受訪分析:
-》訪客分析:
-》轉化路徑分析: