Azure Data Explorer(Kusto)学习笔记
Azure Data Explorer 指南
Azure在2018年推出了Data Explorer產品,提供實時海量流數據的分析服務(非流計算),面向應用、網站、移動端等設備。
用戶可以查詢,并交互式地對結果進行分析,以達到提升產品、增強用戶體驗、監控設備、用戶增長等目的。其中提供一些機器學習函數,能夠進行異常、模式識別、并且發現數據中的趨勢。
該服務面向秒-分鐘級拿到結果的場景,類OLAP,對TP場景不敏感。
產品起源
Azure Data Explorer(ADE)內部代號叫Kusto,在Kusto之前,Azure對監控和分析場景散落在各產品中,例如:Log Analytics、Application Insight,Azure Monitor,Time Series Insight,這些產品在用不同的技術架構來解決不同數據源等問題,例如:
-  通過PerfCounter和Event通過流數據進行聚合告警 
-  利用通用計數器寫入時序數據庫,配置實時Dashboard 
-  把應用數據寫到數倉做深入分析 
?
ADE的目標是對上層預定義計算、后計算做一層抽象:將原始數據進行通用存儲,保留一段時間(例如幾個月),對這些多樣化數據進行快速的多維分析。
ADE在微軟的內部代號為Kusto,由以色列研發團隊提供。Azure Log Analytics開始選型是Elastic Search,每年付1M$用來獲得支持,但效果不好,因此在2015年時對日志、Metric場景使用Kusto來提供,包括之前在cosmosDB中的分析工作。
截止 September 2018 的數據:
-  hundreds of teams within Microsoft 
-  41 Azure regions as 2800 Engine+DM cluster pairs 
-  about 23000 VMs. 
-  overall data size stored in Kusto and available for query is 210 petabytes 
-  6 petabytes ingested daily. 
-  around 10 billion queries per month. 
可以推測平均存儲時間為:210 (PB) / 6 (PB) = 35 天
產品定義
面向數據類型是Immutable Data,特點是AppendOnly,并且大部分都是Semi-Structure Data,例如User Click Log,Access Log等。Big Data理論中90%都是這類數據,這也是Big Data理論數字化并洞察物理時間的基礎。
從Facebook等數據來看,2017年時每天用戶產生的視頻(UGC)大約在10PB,但用戶點擊產生的日志量已經遠遠超過10PB這量,對視頻網站而言,內容數據增量少于點擊日志的增量已成為通用的規律。
Azure在宣傳時這樣定義自己的產品:
fast, fully managed data analytics service for real-time analysis on large volumes of data streaming from applications, websites, IoT devices, and more.產品主要解決三類問題:
-  Customer Query (Advance Hunting) 
-  Interactive UI (前者封裝) 
-  Background Automation(定時任務) 
也有一些解釋基于幾個交互式產品來解釋:底層是實時OLAP,上層是Jupiter(交互式) + Kibana(可視化)
從產品定位角度考慮,ADE處于中間層次(利用人的交互式分析能力進行發掘與探索):
-  integrates with other major services to provide an end-to-end solution 
-  pivotal role in the data warehousing flow by executing the?EXPLORE?step of the flow on terabytes of diverse raw data 
除此之外ADE(Kusto)是
-  azure application insight, log analytics 基礎 
-  為Azure Monitor,?Azure Time Series Insights, and?Windows Defender Advanced Threat Protection提供數據服務 
-  提供REST API, MS-TDS, and Azure Resource Manager service endpoints and several client libraries 
數據模型與API
ADE以實例方式給用戶付費,用戶購買一組實例后可以創建:
-  Database 
-  Table:存儲實例,包含Schema(表結構和字段類型),Mapping(如何從CSV、Avro等格式映射) 
-  Functions:自定義函數,利用scalar語言可以定義自定義方法,方便后期處理 
整個API只有一組接口,通過類KQL方法來管理控制流與數據流,控制流以”.”作為開頭,例如 “.create table”。數據分析語言除了KQL外還支持SQL:
-  TSQL:?https://docs.microsoft.com/en-us/azure/kusto/api/tds/t-sql 
-  KQL:?https://docs.microsoft.com/en-us/azure/kusto/query/index 
以下是一些案例:
創建: .create table MyLogs ( Level:string, Timestamp:datetime, UserId:string, TraceId:string, Message:string, ProcessId:int32 ) ? 創建或追加: .create-merge tables MyLogs (Level:string, Timestamp:datetime, UserId:string, TraceId:string, Message:string, ProcessId:int32), MyUsers (UserId:string, Name:string) ? .alter column ['Table'].['ColumnX'] type=string 更改列行為后,之前數據會變成Null,建議把數據篩選出來寫入新的Table ? 映射關系: .create table MyTable ingestion csv mapping "Mapping1" '[{ "Name" : "rownumber", "DataType":"int", "Ordinal" : 0},{ "Name" : "rowguid", "DataType":"string", "Ordinal" : 1 }]’ .create table MyTable ingestion json mapping "Mapping1" '[{ "column" : "rownumber", "datatype" : "int", "path" : "$.rownumber"},{ "column" : "rowguid", "path" : "$.rowguid" }]' ? .ingest into table T ('adl://contoso.azuredatalakestore.net/Path/To/File/file1.ext;impersonate') with (format='csv’) .set RecentErrors <| LogsTable | where Level == "Error" and Timestamp > now() - time(1h) .ingest inline into table Purchases <| Shoes,1000 Wide Shoes,50 "Coats, black",20 "Coats with ""quotes""",5 .export async compressed to csv ( h@"https://storage1.blob.core.windows.net/containerName;secretKey", h@"https://storage1.blob.core.windows.net/containerName2;secretKey" ) with ( sizeLimit=100000, namePrefix=export, includeHeaders=all, encoding =UTF8NoBOM ) <| myLogs | where id == "moshe" | limit 10000 .export async to sql MySqlTable h@"Server=tcp:myserver.database.windows.net,1433;Database=MyDatabase;Authentication=Active Directory Integrated;Connection Timeout=30;" <| print Id="d3b68d12-cbd3-428b-807f-2c740f561989", Name="YSO4", DateOfBirth=datetime(2017-10-15) .set table Employees policy ingestiontime true ? Employees | where cursor_after('') ? Employees | where cursor_after('636040929866477946') // -> 636040929866477950 Employees | where cursor_after('636040929866477950') // -> 636040929866479999 Employees | where cursor_after('636040929866479999') // -> 636040939866479000 Tagging(用來管理Extent) ? .ingest ... with @'{"tags":"[\"drop-by:2016-02-17\"]"}' .drop extents <| .show table MyTable extents w 創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的Azure Data Explorer(Kusto)学习笔记的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: 微信申请信用卡不通过怎么办
- 下一篇: 微信申请信用卡怎么查进度
