fluentdでログ収集
fluentd http://fluentd.org/
・複数のアプリケーションサーバーのログを集約、分散等も可能
・イベント毎の振り分けが簡単
・出力先
基本的にやりたいことは全部出来るし、みなさん利用しているようなので使ってみる。
自分で作った変なのをやめて全部こちらに移行する。
> syslogdの話
> http://www.atmarkit.co.jp/flinux/rensai/newlog01/newlog01a.html
| APP Server | | Log Server
| app → fluentd(td-agent) ⇒A⇒ fluentd → 好きな出力B
APP server
input socket <> output forward
A. ログの転送 app to log server
http://docs.fluentd.org/articles/out_forward
分散、失敗した時はファイルに書き出す。
td-agent.conf
include conf.d/*.conf
<source>
type unix
path /var/run/td-agent/td-agent.sock
</source>
<match **>
type file
path /var/log/td-agent/other.log
</match>
conf.d/appname.conf
type forward
send_timeout 60s
recover_wait 10s
heartbeat_interval 1s
phi_threshold 8
hard_timeout 60s
<server>
host 192.168.0.11
port 20011
</server>
# secondary host is optional
<secondary>
type file
path /var/log/fluent/foward-app.appname
</secondary>
</match>
B. ファイルに書き出す。
input http <> output file
http://docs.fluentd.org/articles/out_file
ローテーションなど
<match app.appname.**>
type file
path /var/log/td-agent/appname
time_slice_format %Y%m%d
time_slice_wait 10m
time_format %Y%m%dT%H%M%S%z
compress gzip
#utc
</match>
# httpで受ける
<source>
type forward
port 20011
bind 0.0.0.0
</source>
## live debugging agent
<source>
type debug_agent
bind 127.0.0.1
port 20012
</source>
* source は http ではなく forward
これだけでとりあえずOK
・受け側を起動。
(出力出来ない状態だとエラーが出ずに?失敗します。
2013-01-22 22:49:25 +0900: process finished code=0
2013-01-22 22:49:25 +0900: process died within 1 second. exit.
・送り側を起動
phpから利用する。
http://docs.fluentd.org/articles/php
* autoloaderはオリジナルです。
直接書き込む
$logger = Fluent\Logger\HttpLogger::open(“192.168.0.11″,”20011″);
$ret = $logger->post(“debug.test”,array(“hello”=>”world”));
var_dump($ret);
OK
forwardする
$logger = new Fluent\Logger\FluentLogger(“unix:///var/run/td-agent/td-agent.sock”);
$ret = $logger->post(“app.appname.test.follow”, array(“from”=>”userA”, “to”=>”userB”));
fluent.warn {“message”:”temporarily failed to flush the buffer, next retry will be at 2013-01-22 23:57:25 +0900.”,”error”:”no nodes are available”,”instance”:70342469766660}
forward失敗。
udpの20011(設定したポート)を開きました。
OKです。