Open2
fluent-bit これぐらいはやった方がいい設定

tailで読んでhttpで送信するだけの最小限の設定。動くけど本番運用するにはいろいろ足りないので…
[SERVICE]
Flush 5
Daemon Off
Log_Level info
[INPUT]
Name tail
Tag test.log
Path test.log
Parser json
[OUTPUT]
Name http
Match *
Host 127.0.0.1
Port 9901
Format json

- リトライの設定
- デフォルトでは
Retry_Limit 1
なのでoutput失敗時に1回だけリトライしてそこでも失敗すると捨ててしまう - https://docs.fluentbit.io/manual/administration/scheduling-and-retries
- デフォルトでは
- バッファの設定
- デフォルトでは on memory なので停止すると停止時に output できなかったログが消える
- https://docs.fluentbit.io/manual/administration/buffering-and-storage
- https://docs.fluentbit.io/manual/administration/backpressure
- tail posision の指定
- どこまで読み取ったかを記録して再開できるようにしておく
- https://docs.fluentbit.io/manual/data-pipeline/inputs/tail
[SERVICE]
Flush 5
Daemon Off
Log_Level info
scheduler.base 3
scheduler.cap 60
storage.path /var/log/flb-storage/
storage.sync normal
storage.backlog.flush_on_shutdown on
-
Flush
何秒ごとにoutputするか -
scheduler.base
リトライ exponential back off の下限を決める (default: 5(秒)) -
scheduler.cap
リトライの最大間隔(default 2000(秒)なのでデフォルトでリトライを繰り返すと送信先が復活してもなかなか再送されないので注意) -
storage.path
ファイルをバッファに使う時の書き込み先 -
storage.sync
ファイルの書き込みメソッド(normal
でいいのでは?full
にするとfluent-bitがクラッシュしても保持される耐性が付く -
storage.backlog.flush_on_shutdown on
shutdown時に確実にdiskに書き込む(終了時間が延びる可能性がある. default off)
[INPUT]
Name tail
Tag test.log
Path test.log
Parser json
Db test.db
storage.type filesystem
-
db
読み取ったファイルの位置を記録するファイル(SQLite3 db) -
storage.type filesystem
ファイルバッファを使う(デフォルトはmemory)
[OUTPUT]
Name http
Match *
Host 127.0.0.1
Port 9901
Format json
Retry_Limit 10
-
Retry_Limit
リトライ回数を指定 - scheduler.cap と retry_limit の組み合わせでリトライで担保できる最大の時間が決まるので要調整
- storageを指定しない場合、基本的にはメモリをバッファとして入力を積み続ける
- メモリ消費量が増加する恐れがある
- input plugin に
mem_buf_limit
を指定することで、それ以上のメモリ消費を防げる(backpressureが発生する)
- input plugin はoutputに失敗/送信のスループットが追いつかないなどでbackpressureが発生するとpauseする
- tailの場合はファイルをそれ以上読み進めない(posを更新しない)
- ただしファイルがローテートしてしまうと見失う可能性がある
- ネットワークから入力するようなpluginの場合は入力を破棄する
- tailの場合はファイルをそれ以上読み進めない(posを更新しない)