LoginSignup
0
0

More than 1 year has passed since last update.

td-agent | in_exec プラグインでコマンド or スクリプト実行結果を入力として扱う

Last updated at Posted at 2018-06-24

in_exec プラグインでは、指定時間毎にスクリプトを実行して、その結果を入力として扱うことが出来る。

設定

設定ファイルに以下を記述。

例として echo コマンドでJSONを吐き出して入力として扱う。
これをtd-agent側に標準出力させる。

/etc/td-agent/td-agent.conf

<source>
  @type exec
  format json
  tag in_exec_test
  command echo '{ "key" : "vallue" }' # 実行するコマンド
  run_interval 1s # 1秒ごとに実行
</source>

<match in_exec_test>
  @type stdout
</match>

結果

1秒ごとに結果が出力される。

$ td-agent

2018-06-24 08:07:58 +0000 in_exec_test: {"key":"vallue"}
2018-06-24 08:07:59 +0000 in_exec_test: {"key":"vallue"}
2018-06-24 08:08:00 +0000 in_exec_test: {"key":"vallue"}

補足

ruby などのスクリプトで JSON を返すようにしておいてそれをコマンド実行すれば、何か柔軟な結果を返すことが出来る。

環境

  • td-agent 0.12.40
  • Ubuntu 16.04.4 LTS (Xenial Xerus)
  • Docker version 18.03.1-ce, build 9ee9f40

参考

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

Twitter

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