LoginSignup
0
0

More than 3 years have passed since last update.

fluentdのプラグインをgemでインストール

Last updated at Posted at 2019-10-31

gemでのfluentdプラグインのインストール方法を確認しました。

S3へ出力するプラグインを試してみます。

Ruby、gemはインストール済みとします。

(rbenvの環境下で試したので、以下の例ではgem installを一般権限で実行してます。場合によってはsudoが必要です)

fluentdインストール

$ gem install -N fluentd
$ fluentd --version
fluentd 1.7.4

シンプルな設定ファイルとして以下のファイルを作成します。

sample.conf
<source>
  @type tail
  path input.txt
  pos_file input.pos
  tag test
  <parse>
    @type none
  </parse>
</source>
<match test>
  @type s3
  s3_bucket xxx
  path fluentd-sample-log
  <buffer>
    chunk_limit_records 1
  </buffer>
</match>

@type s3でoutputプラグインとしてs3を指定しています。s3プラグインはあとでインストールします。

s3_bucket xxxのところは自分の試せるバケット名を指定します。

chunk_limit_recordsの設定は、バッファリングの容量を1レコードのみにして実質バッファリングせずに入力されたらすぐに出力することを指示するものです。

入力のファイルを作っておきます。

$ touch input.txt

fluentdを起動してみます。

$ fluentd -c sample.conf

Unknown output plugin 's3'. Run 'gem search -rd fluent-plugin' to find plugins"
というエラーが表示されてしまいます。

プラグインインストール

プラグインをインストールします。

$ gem install fluent-plugin-s3
$ fluentd -c sample.conf

別のターミナルで以下のようにすると、

$ echo hello >> input.txt

S3のバケットの中身を見ると、データが保存されているのが確認できます。chunk_limit_records 1なので、1ファイルに1レコードのみが含まれます。

$ aws s3 ls s3://xxx/
2019-10-29 12:08:36         71 fluentd-sample-log20191029_0.gz
$ aws s3 cp s3://xxx/fluentd-sample-log20191029_1.gz - | gunzip
2019-10-29T12:08:34+09:00       test    {"message":"hello"}

結論

fluentdインストール時に含まれるfluent-gemの役割がわからなかった。普通のgemでもできてしまった。fluentdで使われるRubyとgemコマンドのRubyが一致していれば、どちらでも問題ないということでしょうか。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0