1.fluentd說明
參考官網(wǎng)https://www.fluentd.org/定義,fluentd是一套開源的日志收集器槽卫,類似ELK中l(wèi)ogstash、阿里云的logtail這樣的服務(wù)。
2.可用配置(基于windows)
<match test.*.*>
@type forest
subtype file
<template>
time_slice_format %Y-%m-%d
output_tag false
output_time false
path C:\opt\td-agent\log\${tag_parts[0]}
# format single_value
flush_interval 2s
buffer_path C:\opt\td-agent\buffer\${tag_parts[0]}
append true
num_threads 1
</template>
</match>
上面是一套匹配test..這樣tag的日志收集配置,具體說明:
2.1@type forest
指定使用的type越庇,這里是用的forest,一種input 插件奉狈;前提是需要安裝模塊:
fluent-gem install fluent-plugin-forest
2.2根據(jù)時(shí)間分割
time_slice_format %Y-%m-%d 表示按天
2.3去掉默認(rèn)添加的時(shí)間和tag
output_tag false
output_time false
2.4 format single_value
可用于單列提取卤唉,比如原始日志有多個(gè)字段但是我們只需要一列,這時(shí)候就可以使用
2.5 tag_parts
這個(gè)是系統(tǒng)變量仁期,是指tag根據(jù)點(diǎn)號(hào)分割的數(shù)據(jù)桑驱,下標(biāo)從0開始。比如我的tag是test.action.pay跛蛋,那么${tag_parts[1]}就是action
3 其它
3.1 性能比較
沒有具體測(cè)試過熬的,網(wǎng)上分析fluentd是優(yōu)于logstash,但是插件豐富程度要差一些赊级。
具體見:https://lintingbin2009.github.io/2018/10/04/Fluentd%E6%80%A7%E8%83%BD%E4%BC%98%E5%8C%96%E5%AE%9E%E8%B7%B5/
3.2 優(yōu)化
flutentd是基于Ruby開發(fā)押框,Ruby有全局鎖(GIL),因而在一個(gè)Ruby進(jìn)程里面同時(shí)最多只有一個(gè)線程在運(yùn)行理逊。這樣的話橡伞,Ruby的多線程對(duì)需要更多計(jì)算資源的操作顯得無(wú)能為力,所以這會(huì)影響fluentd的性能挡鞍,建議通過多進(jìn)程來(lái)充分使用多核CPU骑歹,推薦部署架構(gòu):
綜合
總體來(lái)看fluentd使用還是比較簡(jiǎn)單方便的,值得學(xué)習(xí)和使用下墨微,具體性能方面后期有進(jìn)一步研究再補(bǔ)充道媚。