Help us understand the problem. What is going on with this article?

Fluentdでプラグインを使うと便利になる

More than 3 years have passed since last update.

概要

以下を使って、データの内容によってファイル名、パスを動的に変えて出力するメモ

  • rewrite_tag_filter
  • file_alternative

こんなかんじ↓

試しにやってみよう

1. 「tag」と呼ばれる情報でデータを管理する

  ※tagを付けるってことは、レコードごとにラベル付ける感じです

<source> 
  //データを格納するファイル名を指定
   @type tail path /var/tmp/data.csv
   //読み込んだ位置を記録するファイルを指定する。(  fluentd daemon を再起動したい場合などの場面でその続きから再開して読み込んでくれる)
    pos_file /var/tmp/data.log.event.pos  

  //各レコードに対してタグを指定する
   tag foo.id 

 //出力するデータのフォーマットを作る 
    format /^(?<fooid>[^,]*),(?<foodata>.*)$/ 
</source> 

こうなります

2. rewrite_tag_filterでレコードにタグを付ける

<match foo.id> 
  //レコードの内容に応じてタグを変更することが出来るプラグイン
    @type rewrite_tag_filter 
   //レコードにタグをつける
    rewriterule1 fooid (.*) bar.id.$1 
</match> 

こうなります

3. file_alternativeとforestでtagによってファイル名、パスを動的に変える

<match bar.id.*>
    @type copy 
    <store> 
         type forest 
     //タグの一部をディレクトリやファイル名に利用するプラグイン
         subtype file_alternative 
         <template> 
                // 利用したい要素を選ぶ ${tag_parts[0]}=bar ${tag_parts[1]}=id
             path /var/tmp/${tag_parts[2]}/rawdata.csv
         </template>
    </store>
</match>

こうなります

起動
/etc/init.d/td-agent restart

設定ファイル
vi /etc/td-agent/td-agent.conf

プラグインインストール
cd /usr/sbin/
./td-agent-gem install fluent-plugin-rewrite-tag-filter
./td-agent-gem install fluent-plugin-file-alternative
./td-agent-gem install fluent-plugin-forest

yococo
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした