8. 處理 Log 時,遇到甚麼問題?-(2)
• 不同的 Log 格式
• CPU , disk , network usage
• Syslog, Windows logs, Application logs
• Apache, Nginx, IIS, MySQL, MS SQL, Oracle, etc.
• ERP, CRM, E-Commerce, etc.
• Networking, Firewall logs
• Social networking, User access logs
• word, pdf, csv, html web page, etc.
8
9. 處理 Log 時,遇到甚麼問題?-(3)
• 不同的日期格式
• 142920788
• Oct. 12 23:21:45
• [5/May/2016:08:09:10 +0000]
• Tue 01-01-2016 6:00
• 2016-08-01 T 05:45 UTC
• Sat Jul 23 02:16:57 2016
• 08:21, 06 August 2016(UTC)
9
10. 處理 Log 時,遇到甚麼問題?-(4)
• Log 散佈在各伺服器上,非集中管理。
• 日誌紀錄檔分布各處
• 需登入每台伺服器處理
• IT 維運人員需使用各種指令及工具來蒐集
• Linux syslog - tail / grep / sed / awk /sort /cut
• Windows system - admin GUI console / powershell script /vbscript
• Hadoop / Spark log tools
• Database - Oracle / Mysql /MS SQL / MongoDB Tools
• Application Server - IIS Log / Apache log /Nginx Tools
10
19. Logstash Introduction
• 2009年由 Jordan Sissel 發布
• 於 2013年8月27日加入 Elastic
• Framework for managing logs
• Founded by Jordan Sissel
• JRuby
• Mainly consists of 3 components:
• input : passing logs to process them into machine understandable
format(file,lumberjack).
• filters : set of conditionals to perform specific action on a
event(grok,geoip).
• output : decision maker for processed event/log(elasticsearch,file)
19
20. Kibana Introduction
• 2011年12月11日由 Rashid Khan 發布的 PHP 版本
• 2012年8月19日發布由 Ruby 重寫的 Kibana 2 版本
• 2013年1月10日加入 Elastic
• 2014年2月發布 Angularjs 版本 Kibana 3
• 2015年3月發布 JRuby 及 Node.js 版本的 Kibana 4
• Powerful front-end dashboard for visualizing indexed
information from elastic cluster.
• Capable to providing historical data in form of
graphs,charts,etc.
• Enables real-time search of indexed information.
20
27. Lucene 基本概念(1)
• Index – 儲存資料
• file or ram based
• write once ,read many segment
• append mode (no update and delete)
• Segment – 索引會被分成很多 Segment
• Document – 資料儲存於 Index 的通稱,或說是原始資料的載體。
• Field - Document 的一部份,最基本的有 name, value 屬性。
• Term – 原始內容裡的一個詞,搜尋的最小單位。
27
29. Lucene 基本概念(2)
• Token – Term 在某個 Field 的儲存格式,包含了
• Term 內容、
• Term 類型
• Term 在原始內容的起始及長度,
• 在文章內容的重要程度值(boost權重) (basic :TF / IDF)
• Term vector
• Add, update, Delete 的動作在未寫入磁碟之前,資料都存在記
憶體內,透過 Flush to disk (Commit) 寫入磁碟中。
• Delete 在未 (Optimized or segment merge) 前都還儲存在
index 中,且只是標記已刪除。
29
30. TF/IDF
• Term 於文章內容的重要程度值
• TF – Term frequency
• 以 Luhn algorithm 為基礎
• Term 在一篇文章中出現的次數
• IDF - Inverse Document Frequency
• 被用來更精確的計算 Term 的重要性程度
• 有多少 Document 包含了此 Term ?
30
31. Lucence Analyzer(1)
• 每個 Field 都需設定 Analyzer 與 Querying
• Analyzer :
• 包含了0 或多個 Tokenizers 及 Filters
• Tokenizer 負責把資料分析後,轉為很多 Token。
• Filter 負責處理如:大小寫轉換、Synonyms、language , etc.
• Querying :
• 通常與上面的 Analyzer 一致
• Syntax 包含 AND, OR(default) , NOT.
• query all or specific fields
• ?, * for wildcards
• ~ for fuzzy search
• ^ for boost value
• Escape 跳脫字元
31
38. Elasticsearch APIs 介紹
• Create Index API
• CRUD 增、查、修、刪
• (C) Indexing API
• (R) Get index API
• (U) Update API
• (D) Delete API
• Exists API
• Multi Get API
• Bulk API
• Mapping API
• Search API
• Explain API
38
39. Create Index API
• Create 時若沒有特別設定,會使用預設值。
• 建議自行設定合適的 Shard, Replica, Analyzer。
• Mapping 可是之後再設定。
39
40. Create document API
• Indexing Documents into the Index
• Http status code
• 201 表示新建立
• 200 為更新或重新建立索引
• _id 可由系統自動產生或外部輸入
• Documents 可以設定生命週期 (TTL),系統會自動回收過期的 Index。
• Index 使用分散式儲存方式,切分多個 Shards。
• document indexed 後,回傳 _version 版本編號.
40
41. Get API
• 即時的對 Index 執行查詢
• Http Status code
• 200 for found
• 404 for not found
• 可針對特定欄位進行查詢,預設為對 _all 欄位查詢。
41
42. Update API
• 可指定更新某一個 document 的特定欄位
• 內部運作
• 先以 Get 取得該 document 內容
• 刪除該 _id 的 document
• 比對新舊內容,並合併內容.
• 執行 Index 建立索引
42
43. Delete API
• 刪除 Document
• Http status code
• 200 for delete
• 404 for not found
• 更新 Document 的 _version 版本編號
• 回傳更新後的 _version
43
44. Exists API
• 確認 Document 是否存在 Index?
• Http status code
• 200 for found
• 404 for not found
44
57. Elasticsearch 重要名詞列表
57
Relational Database Elasticsearch
Database Index
Table Type
Row (Tuple) Document
Column Field
Schema Mapping
Partition Shard
SQL Query DSL (domain specific language)
Replica
Instance Node
Cluster Cluster
58. Elasticsearch 與 Lucene
• Provided by Lucene
• Document analysis
• Indexing
• Query
• Results
• Provided by Elasticsearch
• Distribution
• Restful API
• Administration
• Wrappers to Indexing and querying
• Plugins
58
59. Data models of Elasticsearch
• Data is stored as JSON format
• string, number, date, byte, lat-long etc.
• schema free (static or dynamic)
• Fields can be indexed, stored or analyzed.
• Internal meta fields:
• _id, _type, _source, _version, etc.
• Settings and mappings 可以依照需求而設定
59
62. Elasticsearch 名詞- Index
• Index - 為 Elasticsearch 儲存資料的地方,相當於 RDBMS 的
Database。
• 通常會把相同特性的資料儲存在同一個索引名稱中。
62
引用:https://www.youtube.com/watch?v=LDyxijDEqj4
63. Elasticsearch 名詞- Type, Document
• Type - 就如 Table ,一個 Index 可以是多個 Type 組成。
• Document – 儲存資料的最小單位,需要有 Unique Id,由
Elasticsearch API 取出時為 Json 格式。
63
引用:http://insightdataengineering.com/blog/elasticsearch-crud/
64. Elasticsearch 名詞- Fields
64
屬性s 說明 資料型態
Field name 定義欄位的名稱;預設值是欄位本身的名字 all
type 定義欄位的資料型態,參考下一張簡報
store Yes , no => yes 表示儲存原始資料於 index 內,no 是不儲存,預設 no all
index
Analyzed, not_analyzed , no => 預設值是analyzed
• analyzed 索引且分析來源資料為 terms
• not_analyzed 索引但是不分析
• no 不提供索引,也就是無法針對此欄位查詢資料
來源為文字字串 string
其他類型只能為
no 或 not_analyzed
null_value 如果欄位為空值時,可設定預設值,比如 "null_value" : ”nil" all
boost 欄位權重,預設為 1.0 all
index_analyzer 建立索引時用的 analyzer all
search_analyzer 查詢索引時用的 analyzer all
analyzer
設定索引和查詢時用的 analyzer,Elasticsearch 預設使用 standard analyzer
內建的還有如: whitespace, simple, english analyzer
all
include_in_all
true, false => 預設值是true
預設 elasticsearch 會為每個欄位的值建立索引,並儲存在 _all 欄位中,這樣每個欄位都可以被查詢到,你可
以關閉它 include_in_all = false
all
norms
Norms 在 indexing tisme 時去計算開欄位的重要性,有助於查詢結果的 Ranking 排序。
在 index 屬性設定為 analyzed 時,此預設值為 true, not_analyzed 時為 false
all