JKになりたい

何か書きたいことを書きます。主にWeb方面の技術系記事が多いかも。

LogstashのMultiple-Pipelinesを使う

確か5系まではmainのpipelineしかありませんでした。

なので、こんな感じでtagなどでoutput先を切り替えたりしてました。。

output {
  if "hoge_feed" in [tags] {
    elasticsearch {
      hosts => ["http://127.0.0.1:9200"]
      index => "hoge"
      document_id => "%{item_id}"
      template => "/usr/share/logstash/templates/hoge.json"
      template_name => "hoge_index"
      manage_template => "true"
      template_overwrite => "true"
    }
  }
}

(hoge.conf)

6系からはMultiple-Piplineが使用できるようになったので、これを使っていきます。

使い方は簡単で、piplines.ymlをpath.setting配下に設置するだけです。

- pipeline.id: APipline
  path.config: "/usr/share/logstash/pipeline/hoge.conf"
  queue.type: persisted
- pipeline.id: BPipline
  path.config: "/usr/share/logstash/pipeline/hogehoge.conf"
  queue.type: persisted

(piplines.yml)

ユニークなpipline.idを決めて、confファイルのパスを指定するだけです。 あとはいろいろなオプション。 設定できるオプションはドキュメント参照。

www.elastic.co

これをpath.settingsにおいて、Logstashを-fオプションなど指定せずに起動するとpiplines.ymlの設定が適用されます。

動かない時に確認する事とか注意する事とか。

パイプラインのリソース

piplineのデフォルト値は、単一のpipline前提で設定されています。

pipeline.workersのデフォルト値は「Number of the host’s CPU cores」です。。

この辺りは調整した方が良さそうです。

piplines.ymlの置き場所

piplines.ymlはpath.settings配下に置きます。

path.settingsの場所は、デフォルトでは以下のような設定なっています。

(1).zip .tar.gzから解答した場合 → {extract.path}/config

(2)Debian package, RPM packageからインストールした場合→/etc/logstash

(3)公式のDocker Imageを使用している場合→/usr/share/logstash/config

ディレクトリレイアウトは↓に詳しく載っています。

www.elastic.co

起動時のオプション

Logstashの起動時に
-e, --config.stringや-f, --path.config オプションを指定するとpipelines.ymlを無視します。(警告がログにでます)

これでif文使ったり、プロセスわけたりする必要がなくなりました・・!ありがたい。