fluentdの一時的labelの書き換え
fluent(td-agent)を使用したlabel切り分けで一時的設定→送信時変更する対応が発生したので設定時でのメモ。
sourceディレクティブが複数あり、送信時にsubgroup化して送りたい場合に有効。
sourceディレクティブにsubgroup機能が無い為、送信時のlabelディレクティブ時に追加。
汎用性がありそうな為、調査・対応を下記へ記載しておく。
- 以下構築要件
- sourceディレクティブで一時的に送信時のグループ名をlabel割り当
- 一時的割り当てしたグループ名にtd-agent送信時のsubgroupを追加
- labelを本来設定する名称へ変更
以下td-agent2環境fluentd v0.12以降のバージョン
向けの設定例
<source> @id test_id @type config_expander <config> @type tail @label @testgroup read_from_head true path {log_path}.log pos_file {posfilepath}.pos format multiline format_firstline /^\[\d{4}.\d{2}.\d{2}/ format1 /^\[(?<time>\d{4}.\d{2}.\d{2}\s\d{2}:\d{2}:\d{2})\]\s(?<log_line>.*)/ message_key log_line tag testtag </config> </source> <label @testgroup> <filter **> @type record_transformer <record> loginfo.subgroup testgroup </record> </filter> <match> @type relabel @label @testlabel </match> </label>
後は、送信時のmatchディレクティブでよしなに設定すれば送信される。