[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
SlideShare a Scribd company logo
fluentd ~log collector tool~
         Teck-Talk TIS Daisuke Ikeda
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
Architecture of fluentd
3段階構成
Input        Buffer    Output
                       ・file
・syslog      ・memory   ・AmazonS3
・httpリクエスト   ・file     ・DB
                       ・Zabbix
・file                  などなど
などなど
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というパッケージからもインストール可
ログを送信する側、受信する側両者にインストール
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
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}
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)
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>
fluent-plugin-zabbix
zabbix item設定
fluent-plugin-zabbix
fluent-catでログ送付
$ echo '{"fluent1":"test-log"}' | fluent-cat stats.zabbix


結果
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>
fluent-plugin-mongo
MongoDBのデータ確認
# mongo localhost:27017
> use fluent
switched to db fluent
> show collections
fluent
system.indexes
> db.fluent.find()
{ "_id" : ObjectId("4fbb0dab2663b31095000001"), "mongo"
: 1000, "time" : "Tue May 22 2012 12:52:56 GMT+0900
(JST)" }
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)"
 }
Sample Application
Node.js + mongoose + mongoDB + fluentdで
ログを表示・検索できるWebアプリ作ってみた

                          JSONオブジェクトでデータを扱えるので
                          この組み合わせが非常にやりやすい




                            一括管理して検索機能とかあれば非常
                            に便利になるのでは
Closing
●   ログの管理という点で非常に柔軟性がある
●   とにかく盛り上がっている
●   pluginも大量に出てきている
●   Zabbixとうまく組み合わせて可視化してみると楽しいかも

● 使ってみてちょっと気になった点
    ○ apache ログをmongoDBに格納する際に少しタイムラグ
      あり?
      →Bufferのレイヤの挙動を今後確認予定

More Related Content

社内向けTech Talk資料~Fluentdの基本紹介~

  • 1. fluentd ~log collector tool~ Teck-Talk TIS Daisuke Ikeda
  • 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
  • 3. Architecture of fluentd 3段階構成 Input Buffer Output ・file ・syslog ・memory ・AmazonS3 ・httpリクエスト ・file ・DB ・Zabbix ・file などなど などなど
  • 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>
  • 12. fluent-plugin-mongo MongoDBのデータ確認 # mongo localhost:27017 > use fluent switched to db fluent > show collections fluent system.indexes > db.fluent.find() { "_id" : ObjectId("4fbb0dab2663b31095000001"), "mongo" : 1000, "time" : "Tue May 22 2012 12:52:56 GMT+0900 (JST)" }
  • 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のレイヤの挙動を今後確認予定