在此示範樣例中。你将使用分析站點日志檔案的 HDInsight 查詢來深入了解客戶使用站點的方式。借助此分析。你可檢視外部站點一天内對該站點的訪問頻率以及使用者體驗的站點錯誤總結。
在此教程中,你将學習怎樣使用 HDInsight:
連接配接到包括站點日志檔案的 Azure Storage Blob
建立配置單元表以查詢這些日志
建立配置單元查詢以分析資料
使用 Microsoft Excel 連接配接到 HDInsight(使用 ODBC 連接配接)以檢索已分析的資料
已使用群集配置你完畢腳本和查詢所需的全部内容。要将已分析的資料導出到 Microsoft Excel,你必須滿足下面要求:
必須安裝了 Microsoft Excel 2010 或 Microsoft Excel 2013。
基于 Microsoft Excel 的版本号選擇 32 位或 64 位版本号。
下面是此示範樣例使用的站點日志資料位置。你可從此頁頂部的檔案浏覽器頁籤訪問此資料。也能夠在 [default storage account]/[defaultcontainer]/HdiSamples/WebsiteLogSampleData/SampleLog 路徑下訪問此示範樣例的資料。
站點日志資料
wasb://[email protected]/HdiSamples/WebsiteLogSampleData/SampleLog/
下面配置單元語句建立了一個外部表。同意配置單元查詢存儲在 Azure Blob 存儲中的資料。
外部表以初始檔案格式保留資料,同一時候同意配置單元針對檔案内的資料運作查詢。
配置單元語句通過描寫叙述檔案内的字段、字段間的界定符以及 Azure Blob 存儲中檔案的位置建立了名為網絡日志的新表。在此教程的建立配置單元查詢以分析資料章節,你将針對存儲在此表中的資料運作查詢。
CreateExternal Table weblogs
DROP TABLE IFEXISTS weblogs;
--create tableweblogs on space-delimited website log data
CREATE EXTERNALTABLE IF NOT EXISTS weblogs(s_date date, s_time string, s_sitename string,cs_method string, cs_uristem string,
cs_uriquerystring, s_port int, cs_username string, c_ip string, cs_useragent string,
cs_cookiestring, cs_referer string, cs_host string, sc_status int, sc_substatus int,
sc_win32statusint, sc_bytes int, cs_bytes int, s_timetaken int )
ROW FORMATDELIMITED FIELDS TERMINATED BY ' '
STORED ASTEXTFILE LOCATION'wasb://[email protected]/HdiSamples/WebsiteLogSampleData/SampleLog/'
TBLPROPERTIES('skip.header.line.count'='2');
下面配置單元查詢基于網絡日志表上運作的查詢建立了兩個新表。新表名為 clienterrors 和 refersperday。
clienterrors 的查詢從介于 400 到 500 之間的 HTTP 狀态代碼的網絡日志表中提取資料。而且按遭遇這些錯誤的使用者以及錯誤代碼類型對其進行分組。狀态代碼的範圍介于 400 到 500 之間,通過網絡日志表中的 sc_status 清單示,相應訪問站點時用戶端遭遇的錯誤。
然後,提取的資料按每一個錯誤代碼的發生次數進行排序并寫入 clienterrors 表。
refersperday 的查詢從引用此站點的全部外部站點的網絡日志表中提取資料。外部站點資訊從網絡日志表的 cs_referer 列中提取。為了確定引用連結不遭遇錯誤,表僅顯示傳回 200 到300 之間的 HTTP 狀态代碼的頁面資料。然後,提取的資料将寫入 refersperday 表。
DROP TABLE IFEXISTS ClientErrors;
--create tableClientErrors for storing errors users experienced and their frequencies
CREATE EXTERNALTABLE ClientErrors(sc_status int, cs_referer string, cs_page string, cnt int)
ROW FORMATDELIMITED FIELDS TERMINATED BY ',';
--populate tableClientErrors with data from table weblogs
INSERT OVERWRITETABLE ClientErrors
SELECT sc_status,cs_referer,
concat(cs_uristem,'?',regexp_replace(cs_uriquery,'X-ARR-LOG-ID=[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}',''))cs_page,
count(distinctc_ip) as cnt
FROM weblogs
WHERE sc_status>=400 and sc_status < 500
GROUP BYsc_status, cs_referer, concat(cs_uristem,'?',regexp_replace(cs_uriquery,'X-ARR-LOG-ID=[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}',''))
ORDER BY cnt;
-------------------------------------------------------------------------------------------
DROP TABLE IFEXISTS RefersPerDay;
--create tableRefersPerDay for storing references from external websites
CREATE EXTERNALTABLE IF NOT EXISTS RefersPerDay(year int, month int, day int, cs_refererstring, cnt int)
--populate tableRefersPerDay with data from the weblogs table
INSERT OVERWRITETABLE RefersPerDay
SELECTyear(s_date), month(s_date), day(s_date), cs_referer, count(distinct c_ip) ascnt
WHERE sc_status>=200 and sc_status <300
GROUP BY s_date,cs_referer
ORDER BY cntdesc;
單擊送出以運作先前章節中顯示的查詢。查詢運作下面任務:
從 HDInsight 群集關聯的 Azure Blob 存儲中的原始站點日志資料建立網絡日志表。
建立并填充先前章節中描寫叙述的 clienterrors 和 refersperday 表。
運作查詢時,你可單擊檢視具體資訊來擷取有關背景運作任務的很多其它資訊。在頁底全部作業都處于已完畢狀态後。繼續運作 将資料載入到 Excel。
cs_uriquerystring, s_port int, cs_username string, c_ip string, cs_useragent string,
cs_cookiestring, cs_referer string, cs_host string, sc_status int, sc_substatus int,
sc_win32statusint, sc_bytes int, cs_bytes int, s_timetaken int )
STORED ASTEXTFILE LOCATION 'wasb://[email protected]/HdiSamples/WebsiteLogSampleData/SampleLog/'
--populatetable ClientErrors with data from table weblogs
INSERTOVERWRITE TABLE ClientErrors
SELECTsc_status, cs_referer,
concat(cs_uristem,'?',regexp_replace(cs_uriquery,'X-ARR-LOG-ID=[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}',''))cs_page,
count(distinct c_ip) ascnt
GROUP BYsc_status, cs_referer, concat(cs_uristem,'?
', regexp_replace(cs_uriquery,'X-ARR-LOG-ID=[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}',''))
--populatetable RefersPerDay with data from the weblogs table
INSERTOVERWRITE TABLE RefersPerDay
GROUP BYs_date, cs_referer
作業會話
查詢名稱
日期
ID
操作
狀态
表中無可用資料
安裝驅動程式後。請使用下面步驟連接配接到表。
1. 打開 Excel 并建立空白的工作表。
2. 從資料頁籤中,選擇來自其它源。然後選擇來自 Microsoft 查詢。

3. 提示選擇資料源時,選擇示範樣例 Microsoft 配置單元 DSN。
4. 在 Microsoft 配置單元 ODBC 驅動器連接配接對話框中。輸入下面值,然後單擊“确定”。
主機 - HDInsight 群集的主機名。比如。mycluster.azurehdinsight.net
使用者名 - HDInsight 群集的管理者名稱
password - 管理者password
全部其它字段均為預設值。
5. 在查詢向導中。選擇 refersperday 表。然後選擇 > button。
6. 單擊下一步繼續檢視向導,直到到達帶有完畢button的對話框。
單擊完畢。
7. 出現導入資料對話框後,單擊确定以接受預設值。
完畢查詢後。資料将顯示在 Excel 中。
在本教程中。你了解了怎樣使用 Azure HDInsight 分析使用 Apache Hive 的站點日志資料。你浏覽了一個流程,了解原始資料怎樣先上載到 Azure 存儲空間 Blob 再載入到配置單元表以便運作查詢。最後,你了解了怎樣将配置單元查詢的結果導入到 Microsoft Excel。
假設你具有本教程或其它示範樣例方面的回報。請使用上面的幫助 + 回報連結。
使用下面連結繼續了解怎樣将配置單元和 Excel 與 HDInsight 一同使用。
<a target="_blank" href="http://azure.microsoft.com/en-us/documentation/articles/hdinsight-use-hive/">将配置單元和 HDInsight 中 Hadoop 一同使用</a>
<a target="_blank" href="http://azure.microsoft.com/en-us/documentation/articles/hdinsight-analyze-twitter-data/">使用 HDInsight 中 Hadoop 分析 Twitter 資料</a>
<a target="_blank" href="http://azure.microsoft.com/en-us/documentation/articles/hdinsight-connect-excel-hive-odbc-driver/">使用 Microsoft 配置單元 ODBC 驅動程式将 Excel 連接配接到 Hadoop</a>
<b></b>
<b>本文轉自mfrbuaa部落格園部落格,原文連結:</b><b>http://www.cnblogs.com/mfrbuaa/p/5339896.html</b><b>,如需轉載請自行聯系原作者 </b>