LoginSignup
5
4

More than 5 years have passed since last update.

multiprocessで起動したプロセスもログを取得する

Last updated at Posted at 2015-02-05

multiprocessを利用したconfの作成

fluent-plugin-multiprocess
Multiprocess Input Plugin
上記を参考に起動ファイルを作成してみる。

td-agent.conf
 <source>
   type multiprocess
   <process>
     cmdline -c /etc/td-agent/sub_td-agent1.conf 
     sleep_before_start 1s
     sleep_before_shutdown 5s
   </process>
   <process>
     cmdline -c /etc/td-agent/sub_td-agent2.conf 
     sleep_before_start 1s
     sleep_before_shutdown 5s
   </process>
 </source>

multiprocessを利用して起動

起動ログ

2015-02-05 14:38:57 +0900 [info]: adding source type="multiprocess"
2015-02-05 14:38:57 +0900 [info]: adding match pattern="**" type="stdout"
2015-02-05 14:38:58 +0900 [info]: launching child fluentd -c /etc/td-agent/sub_td-agent1.conf
2015-02-05 14:38:59 +0900 [info]: launching child fluentd -c /etc/td-agent/sub_td-agent2.conf

エラー無く起動しているようだが、
別プロセスとして起動したFluentの起動ログがでていない。
psなどで確認すると6つのプロセスが存在していたので起動はしているようだ。

親プロセス以外のログも取得

td-agent.confを修正
cmdlineにログを吐き出すオプションを付与
※td-agent2を利用しているので、ついでにv1オプションも付与

td-agent.conf
 <source>
   type multiprocess
   <process>
     cmdline -c /etc/td-agent/sub_td-agent1.conf  --log /var/log/td-agent/sub_td-agent1.log --use-v1-config
     sleep_before_start 1s
     sleep_before_shutdown 5s
   </process>
   <process>
     cmdline -c /etc/td-agent/sub_td-agent2.conf --log /var/log/td-agent/sub_td-agent2.log --use-v1-config
     sleep_before_start 1s
     sleep_before_shutdown 5s
   </process>
 </source>

これで起動してやると各プロセスのログが吐出されます。

ログファイルがわかれるのが嫌

ログオプションを付与する方法だとログファイルがわかれてしまうので嫌とかある場合は親プロセスと子プロセスに以下の設定を追加

親プロセス

<source>
  type forward
  port 24230   # 他のプロセスが使ってないポートならなんでも
</source>

<match fluent.**>
  type stdout
</match>

子プロセス

<match fluent.**>
  type forward
  <server>
    host localhost
    port 24230   # 親プロセスで追加したポート
  </server>
</match>

このような設定入れとけば子プロセスで何かあっても親プロセスのログに出力されるはず。
※動作確認してないけどきっとこんなかんじ…
ただ、初回起動時の設定読み込みとかは見れないので、見たい場合は別出ししとくしかないのかなと思います。

他に良い方法あれば教えて下さい。

5
4
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
5
4