More Related Content Similar to 社内向けTech Talk資料~Fluentdの基本紹介~ (20) More from Daisuke Ikeda (20) 社内向けTech Talk資料~Fluentdの基本紹介~ 2. What's fluentd?
Fluentd is an event collector system.
It is a generalized version of syslogd,
which handles JSON objects for its log
messages.※
・イベントログ収集ツール
・JSONオブジェクトとしてログデータを管理可能
・Ruby実装のOSS
※https://github.com/fluent/fluentd
4. Install fluentd
gemパッケージとして提供(Ruby1.9.2以上必須)
# gem install fluentd
Successfully installed msgpack-0.4.7
Successfully installed yajl-ruby-1.1.0
Successfully installed iobuffer-1.1.2
Successfully installed cool.io-1.1.0
Successfully installed http_parser.rb-0.5.3
Successfully installed fluentd-0.10.22
ソースコードからもインストール可
td-agentというパッケージからもインストール可
ログを送信する側、受信する側両者にインストール
5. Configure fluentd
設定ファイルの生成
# fluentd --setup /etc/fluent
# ls /etc/fluent/
fluent.conf plugin
設定(fluent.conf)
source matchの2つを定義
## built-in TCP input ## match tag=debug.** and dump to
## $ echo <json> | fluent-cat <tag> console
<source> <match debug.**>
type forward type stdout
</source> </match>
sourceから取得した内容を
match定義のtagに一致したものをmatchの中身の定義に応じてOutput
6. fluent-cat→output log
fluent-catを使って試しにfluentdに出力
## built-in TCP input <match debug.**>
## $ echo <json> | fluent-cat <tag> type file
<source> path /home/ike-dai/log/fluentd.log
type forward </match>
</source>
fluentd起動
# fluentd -c /etc/fluent/fluent.conf
fluent-catでログ送付
# echo '{"test":12345}' | fluent-cat debug.test1
$ less log/fluentd.log.20120519.b4c06414d3dc93f8c
2012-05-19T22:59:45+09:00 debug.test1 {"test":12345}
7. Plugin of fluentd
fluent-logger (0.4.3)
fluent-plugin-cassandra (0.0.2)
fluent-plugin-couch (0.5.0)
fluent-plugin-dstat (0.1.0)
fluent-plugin-growl (0.0.5)
fluent-plugin-ikachan (0.1.0)
fluent-plugin-kestrel (0.1.0) 各種OutputやInput用のpluginが多数公開
fluent-plugin-librato-metrics (0.2.3) gem insgtallで導入可能
fluent-plugin-mongo (0.6.7)
fluent-plugin-msgpack-rpc (0.2.1)
fluent-plugin-mysql (0.0.2)
fluent-plugin-parser (0.1.0)
fluent-plugin-pghstore (0.1.2)
fluent-plugin-redis (0.2.0)
fluent-plugin-s3 (0.2.2)
fluent-plugin-sns (0.2.1)
fluent-plugin-solr (0.1.1)
fluent-plugin-splunk (0.0.1.1)
fluent-plugin-sqs (0.2.1)
fluent-plugin-zabbix (0.0.1)
8. fluent-plugin-zabbix
gem install
$ gem install fluent-plugin-zabbix
設定ファイル変更
<match stats.**>
type zabbix
zabbix_server localhost
host fluent
name_keys fluent1
add_key_prefix test
</match>
11. fluent-plugin-mongo
gem install
$ gem install fluent-plugin-mongo
設定ファイル変更
<match debug.**>
type copy
<store>
type stdout
</store>
<store>
type mongo
host localhost
database fluent
collection fluent
</store>
</match>
13. fluent-plugin-mongo
apacheのログをmongoに格納
<source> <match apache.access>
type tail type mongo
format apache host localhost
path /var/log/httpd/access_log database log
tag apache.access collection logs
</source> </match>
{ "_id" : ObjectId("4fc2f0642663b30bed000001"),
"host" : "172.19.xx.xx",
"user" : "-",
"method" : "POST",
"path" : "/zabbix/api_jsonrpc.php/api_jsonrpc.php",
"code" : "200",
"size" : "68",
"referer" : "-",
"agent" : "Zbx Ruby CLI",
"time" : "Mon May 28 2012 12:25:29 GMT+0900 (JST)"
}
14. Sample Application
Node.js + mongoose + mongoDB + fluentdで
ログを表示・検索できるWebアプリ作ってみた
JSONオブジェクトでデータを扱えるので
この組み合わせが非常にやりやすい
一括管理して検索機能とかあれば非常
に便利になるのでは
15. Closing
● ログの管理という点で非常に柔軟性がある
● とにかく盛り上がっている
● pluginも大量に出てきている
● Zabbixとうまく組み合わせて可視化してみると楽しいかも
● 使ってみてちょっと気になった点
○ apache ログをmongoDBに格納する際に少しタイムラグ
あり?
→Bufferのレイヤの挙動を今後確認予定