# 正規化日誌工具
Fluentd為一套開源收集軟體,提供了統一資料的中介層,將不同來源如Apache,MySQL,Elasticsearch等服務的資料匯入經由Buffer與資料處理後拋轉至設定的目的,可大幅度去降低資料整合傳遞的複雜度
其特色為
- 由C與Ruby撰寫而成(可透過ruby編寫增加其功能)
- 資料內容以json格式收集與拋送
- 有許多額外的plugin,可自行加入額外的功能
- 透過.conf設定處理資料流程

有兩種Fluentd的安裝
- Fluentd (社區共同維護優化)
- td-agent(由Treasure Data維護)
性能比較為td-agent較優於Fluentd但並非所有作業系統都支援其詳細比較可參照[fluentd與td-agent的比較](https://www.fluentd.org/faqs)
## Plugin擴充
可透過fluent-gem安裝額外的 Plugin 其套件庫[Fluetd Plugins](https://www.fluentd.org/plugins)
```
fluent-gem install fluent-plugin-grep
```
另可利用gem install 非社群套件庫中的Plugin 建議請指定版本(參數 -v)安裝
```
gem install fluent-plugin-elasticsearch -v 2.10.3
```
也能自己撰寫plugin透過執行加入參數(-p)
時掛載額外的plugin目錄運行
```
fluentd -p /path/to/plugin
亦可多次指定目錄
```
撰寫以ruby的方式範例如下
```
# in_my_awesome.rb
require 'fluent/plugin/input'
module Fluent
module Plugin
class MyAwesomeInput < Input
# For `@type my_awesome` in configuration file
Fluent::Plugin.register_input('my_awesome', self)
def configure(conf)
super
end
def start
super
# ...
end
end
end
end
```
查詢以安裝套件及版本
```
$ fluent-gem list
...skip...
fluent-plugin-record-modifier (2.0.1, 0.6.0, 0.5.0)
```
## Fluentd.conf
- Input
- Parser
- Filter
- Output
- Formatter
- Storage
- Service Discovery
- Buffer
### Input
此區決定以何種方式將資料導入至Fluentd中
- in_tail
- in_forward
- in_udp
- in_tcp
- in_unix
- in_http
- in_syslog
- in_exec
- in_sample
- in_windows_eventlog
### Parser
- regexp
- apache2
- apache_error
- nginx
- syslog
- csv
- tsv
- ltsv
- json
- msgpack
- multiline
- none
### Filter
### Output
可分為三種類型 無緩衝、有緩衝區及時間切片(time sliced)
#### 無緩衝(Non-Buffered)
輸出不會緩衝資料並立即執行結果
- out_copy
- out_null
- out_roundrobin
- out_stdout
#### 有緩衝區(Buffered)
![Buffered]()
### Formatter
### Storage
### Service Discovery
### Buffer