Scribe日志收集工具
Scribe日志收集工具
?
概述
Scribe是facebook開源的日志收集系統(tǒng),在facebook內(nèi)部已經(jīng)得到大量的應用。它能夠從各種日志源上收集日志,存儲到一個中央存儲系統(tǒng)(可以是NFS,分布式文件系統(tǒng)等)上,以便于進行集中統(tǒng)計分析處理。它為日志的“分布式收集,統(tǒng)一處理”提供了一個可擴展的,高容錯的方案。當中央存儲系統(tǒng)的網(wǎng)絡或者機器出現(xiàn)故障時,scribe會將日志轉(zhuǎn)存到本地或者另一個位置,當中央存儲系統(tǒng)恢復后,scribe會將轉(zhuǎn)存的日志重新傳輸給中央存儲系統(tǒng)。
scribe的相關資料比較少,主要限于它的主頁(見參考資料1)。此外,它的安裝比較復雜,可參見《scribe日志收集系統(tǒng)安裝方法介紹》。
?
架構(gòu)
?
如上圖所示,Scribe從各種數(shù)據(jù)源上收集數(shù)據(jù),放到一個共享隊列上,然后push到后端的中央存儲系統(tǒng)上。當中央存儲系統(tǒng)出現(xiàn)故障時,scribe可以暫時把日志寫到本地文件中,待中央存儲系統(tǒng)恢復性能后,scribe把本地日志續(xù)傳到中央存儲系統(tǒng)上。
需要注意的是,各個數(shù)據(jù)源須通過thrift向scribe傳輸數(shù)據(jù)(每條數(shù)據(jù)記錄包含一個category和一個message)。可以在scribe配置用于監(jiān)聽端口的thrift線程數(shù)(默認為3)。在后端,scribe可以將不同category的數(shù)據(jù)存放到不同目錄中,以便于進行分別處理。后端的日志存儲方式可以是各種各樣的store,包括file(文件),buffer(雙層存儲,一個主儲存,一個副存儲),network(另一個scribe服務器),bucket(包含多個store,通過hash的將數(shù)據(jù)存到不同store中),null(忽略數(shù)據(jù)),thriftfile(寫到一個Thrift TFileTransport文件中)和multi(把數(shù)據(jù)同時存放到不同store中)。
?
?
scribe的全局配置
| global配置 | 默認值 | 說明 |
| port | 0 | 監(jiān)聽端口 |
| max_msg_per_second | 10000 | 每秒處理的最大消息數(shù) |
| max_quque_size | 5000000 | 消息隊列的大小 |
| check_interval | 5s | store的檢查頻率 |
| new_thread_per_category | yes | yes的話,會為每個category建立一個線程來處理 |
| num_thrift_server_threads | 3 | 線程數(shù) |
例如:
port=1463 max_msg_per_second=2000000 max_queue_size=10000000 check_interval=3?
?
?
store有3種類型:
- 默認store,處理沒有匹配到任何store的category; ? ?配置項:category=default
- 帶前綴的store,處理所有以指定前綴開頭的category;配置項:category=web*
- 復合categories,在一個store里面包含多個category;配置項:categories=rock paper* scissors
?
store配置
| store 配置 | 默認值 | 說明 |
| category | default | 哪些消息被這個store處理,取值范圍:default、、 |
| type | ? | 存儲類型,取值范圍:file、buffer、network、bucket、thriftfile、null、multi |
| max_write_interval | 1s | 處理消息隊列的時間最小間隔 |
| target_write_size | 16K | 當消息隊列超過該值時,才進行處理 |
| max_batch_size | 1MB | 一次處理的數(shù)據(jù)量 |
| must_succeed | yes | 如果一個處理消息失敗,是否重新進入消息隊列排隊,為no時丟棄該消息 |
例如:
<store> category=statistics type=file target_write_size=20480 max_write_interval=2 </store>?
?
下面介紹不同的store類型:
file
將日志寫到文件或者NFS中。目前支持兩種文件格式,即std和hdfs,分別表示普通文本文件和HDFS。可配置的選項有:
例如:
<store> category=sprockets type=file file_path=/tmp/sprockets base_filename=sprockets_log max_size=1000000 add_newlines=1 rotate_period=daily rotate_hour=0 rotate_minute=10 max_write_size=4096 </store>?
?配置解釋:
| file store 配置 | 默認值 | 說明 |
| file_path | /tmp | 文件保存路徑 |
| base_filename | category name | ? |
| use_hostname_sub_directory | no | 為yes的話,使用hostname來創(chuàng)建子目錄 |
| sub_directory | ? | 使用指定的名字來創(chuàng)建子目錄 |
| rotate_period | 創(chuàng)建新文件的頻率 | 可以使用"s"、"m"、"h"、"d"、"w"后綴(秒、分、時、天、周) |
| rotate_hour | 1 | 如果totate_period為d,則取值范圍:0-23 |
| rotate_minute | 15 | 如果totate_period為m,則取值范圍:0-59 |
| max_size | 1GB | 當文件超過指定大小時進行回滾 |
| write_meta | FALSE | 文件回滾時,最后一行包含下一個文件的名字 |
| fs_type | std | 取值范圍:"std"和"hdfs" |
| chunk_size | 0 | 數(shù)據(jù)塊大小,如果消息不超過數(shù)據(jù)塊容量,就不應該跨chunk存儲 |
| add_newlines | 0 | 為1時,為每個消息增加一個換行 |
| create_symlink | yes | 創(chuàng)建一個鏈接,指向最新的一個寫入文件 |
| write_stats | yes | 創(chuàng)建一個狀態(tài)文件,記錄每個store的寫入情況 |
| max_write_size | 1MB | 緩沖區(qū)大小,超過這個值進行flush。該值不能超過max_size配置項的值 |
?
?
network
network store轉(zhuǎn)發(fā)消息到其他scribe服務器上,scribe以長連接的方式批量轉(zhuǎn)發(fā)消息。
例如:?
<store> category=default type=network remote_host=hal remote_port=1465 </store>?
?配置解釋:
| scribe store 配置 | 默認值 | 說明 |
| remote_host | ? | 遠程主機地址 |
| remote_port | ? | 遠程主機端口 |
| timeout | 5000ms | socket超時時間 |
| use_conn_pool | FALSE | 是否使用連接池 |
?
buffer
buffer stores有兩個子stores,分別為"primary"和"secondary",當primary store不可用時,才將日志寫入secondary store(只能是File Stores或Null Stores)。當primary store恢復工作時,會從secondary store恢復數(shù)據(jù)(除非replay_buffer=no)。
例如:
<store> category=default type=buffer buffer_send_rate=1 retry_interval=30 retry_interval_range=10<primary>type=networkremote_host=woprremote_port=1456</primary><secondary>type=filefile_path=/tmpbase_filename=thisisoverwrittenmax_size=10000000</secondary> </store>?
?配置解釋:
| buffer store 配置 | 默認值 | 說明 |
| buffer_send_rate | 1 | 在一次check_interval中,從secondary讀取多少次消息并發(fā)到primary |
| retry_interval | 300s | 在寫primary失敗后,指定重試的時間間隔 |
| retry_interval_range | 60s | 在寫primary失敗后,重試的時間間隔在一個時間范圍內(nèi)隨機選擇一個 |
| replay_buffer | yes | 是否將secondary的消息恢復到primary |
?
?
null
丟棄指定category的消息;
例如:
<store> category=tps_report* type=null </store>?
?
bucket
bucket stores將每個消息的前綴作為key,并hash到多個文件中。
例如:
<store> category=bucket_me type=bucket num_buckets=2 bucket_type=key_hash<bucket0>type=filefs_type=stdfile_path=/tmp/scribetest/bucket0base_filename=bucket0</bucket0><bucket1>...</bucket1><bucket2>...</bucket2> </store>?
配置解釋:
| bucket store 配置 | 默認值 | 說明 |
| num_buckets | 1 | hash表的bucket個數(shù) |
| bucket_type | ? | 取值范圍:key_hash、key_modulo、random |
| delimiter | : | 識別key的前綴分隔符 |
| remove_key | no | 是否刪除每個消息的前綴 |
| bucket_subdir | ? | 每個子目錄的名字 |
?
?
multi
multi store將消息同時轉(zhuǎn)發(fā)給多個子sotres(如store0, store1, store2, ...)。
例如:
<store> category=default type=multi target_write_size=20480 max_write_interval=1<store0>type=filefile_path=/tmp/store0</store0><store1>type=filefile_path=/tmp/store1</store1> </store>?
?
Thriftfile?
Thriftfile store與File store類似,只是前者將消息發(fā)送給Thrift TFileTransport 文件;
例如:
<store> category=sprockets type=thriftfile file_path=/tmp/sprockets base_filename=sprockets_log max_size=1000000 flush_frequency_ms=2000 </store>?
?配置解釋:
| thriftfile store 配置 | 默認值 | 說明 |
| file_path | /tmp | 文件保存路徑 |
| base_filename | category name | ? |
| rotate_period | 創(chuàng)建新文件的頻率 | 可以使用"s"、"m"、"h"、"d"、"w"后綴(秒、分、時、天、周) |
| rotate_hour | 1 | 如果totate_period為d,則取值范圍:0-23 |
| rotate_minute | 15 | 如果totate_period為m,則取值范圍:0-59 |
| max_size | 1GB | 當文件超過指定大小時進行回滾 |
| fs_type | std | 取值范圍:"std"和"hdfs" |
| chunk_size | 0 | 數(shù)據(jù)塊大小,如果消息不超過數(shù)據(jù)塊容量,就不應該跨chunk存儲 |
| create_symlink | yes | 創(chuàng)建一個鏈接,指向最新的一個寫入文件 |
| flush_frequency_ms | 3000ms | 同步Thrift file 到磁盤的頻率 |
| msg_buffer_size | 0 | 非0時,拒絕所有大于該值的寫入 |
?
?
?
參考文檔:
http://dongxicheng.org/search-engine/scribe-installation/
http://dongxicheng.org/search-engine/scribe-intro/
http://blog.octo.com/en/scribe-a-way-to-aggregate-data-and-why-not-to-directly-fill-the-hdfs/
https://github.com/facebookarchive/scribe/wiki/Scribe-Configuration
總結(jié)
以上是生活随笔為你收集整理的Scribe日志收集工具的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: LoadRunner常见问题整理
- 下一篇: 网络基础---物理层