fluentdの複数sourceディレクティブで各label毎に特定record追加
fluent(td-agent)を使用したlabel切り分けで各label毎にrecord追加する対応が発生したので設定時でのメモ。
sourceディレクティブが複数あり、送信時に特定recordを追加して送りたい場合に有効。
汎用性がありそうな為、調査・対応を下記へ記載しておく。
- 以下構築要件
- sourceディレクティブを各label名にて割り当
- 各label毎に特定recordを追加
以下td-agent2環境fluentd v0.12以降のバージョン
向けの設定例
<source> @id in_redis_server @type tail @label @redis-server read_from_head true path /var/log/redis/redis.log pos_file /var/log/td-agent/redis.pos format none message_key log_line tag test.redis.log </source> <source> @id in_redis_sentinel @type tail @label @redis-sentinel read_from_head true path /var/log/redis/sentinel.log pos_file /var/log/td-agent/redis.sentinel.pos format none message_key log_line tag test.redis.log </source> <label @redis-server> <match> @type relabel @label @testlabel </match> </label> <label @redis-sentinel> <filter **> @type record_transformer <record> loginfo.subgroup testgroup input_tag ${tag} last_tag ${tag_parts[-1]} redis_type sentinel </record> </filter> <match> @type relabel @label @testlabel </match> </label>
■出力イメージ
2018-06-29T18:17:41+09:00 test.redis.log {"log_line":"testmessage","loginfo.subgroup":"testgroup","input_tag":"test.redis.log","last_tag":"log","redis_type":"sentinel","loginfo.hostname":"testhost","loginfo.group":"groupname"}
正常にrecord追加出来た。
条件分岐して、個別に情報追記を行う場合に便利に使えそうではある。