Upload
daisuke-ikeda
View
5.697
Download
3
Embed Size (px)
DESCRIPTION
社内での勉強会で発表した資料です。fluentdの基本的な内容を紹介しました。ZabbixやMongoDBとの連携用Pluginについても少し書いています。
Citation preview
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 fluentd3段階構成
Input・syslog
・httpリクエスト
・file
などなど
Buffer・memory
・file
Output・file・AmazonS3・DB・Zabbixなどなど
Install fluentdgemパッケージとして提供(Ruby1.9.2以上必須)
ソースコードからもインストール可td-agentというパッケージからもインストール可
ログを送信する側、受信する側両者にインストール
# gem install fluentdSuccessfully installed msgpack-0.4.7Successfully installed yajl-ruby-1.1.0Successfully installed iobuffer-1.1.2Successfully installed cool.io-1.1.0Successfully installed http_parser.rb-0.5.3Successfully installed fluentd-0.10.22
Configure fluentd設定ファイルの生成
設定(fluent.conf)source matchの2つを定義
# fluentd --setup /etc/fluent# ls /etc/fluent/fluent.conf plugin
## built-in TCP input## $ echo <json> | fluent-cat <tag><source> type forward</source>
## match tag=debug.** and dump to console<match debug.**> type stdout</match> sourceから取得した内容を
match定義のtagに一致したものをmatchの中身の定義に応じてOutput
fluent-cat→output logfluent-catを使って試しにfluentdに出力
fluentd起動
fluent-catでログ送付
# fluentd -c /etc/fluent/fluent.conf
## built-in TCP input## $ echo <json> | fluent-cat <tag><source> type forward</source>
<match debug.**> type file path /home/ike-dai/log/fluentd.log</match>
# 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 fluentdfluent-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)fluent-plugin-librato-metrics (0.2.3)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)
各種OutputやInput用のpluginが多数公開gem insgtallで導入可能
fluent-plugin-zabbixgem 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-zabbixzabbix item設定
fluent-plugin-zabbixfluent-catでログ送付
結果
$ echo '{"fluent1":"test-log"}' | fluent-cat stats.zabbix
fluent-plugin-mongogem 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-mongoMongoDBのデータ確認
# mongo localhost:27017> use fluentswitched to db fluent> show collectionsfluentsystem.indexes> db.fluent.find(){ "_id" : ObjectId("4fbb0dab2663b31095000001"), "mongo" : 1000, "time" : "Tue May 22 2012 12:52:56 GMT+0900 (JST)" }
fluent-plugin-mongoapacheのログをmongoに格納
<source>type tailformat apachepath /var/log/httpd/access_logtag apache.access</source>
<match apache.access> type mongo host localhost database log collection logs</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 ApplicationNode.js + mongoose + mongoDB + fluentdで
ログを表示・検索できるWebアプリ作ってみた
JSONオブジェクトでデータを扱えるのでこの組み合わせが非常にやりやすい
一括管理して検索機能とかあれば非常に便利になるのでは
Closing● ログの管理という点で非常に柔軟性がある
● とにかく盛り上がっている
● pluginも大量に出てきている
● Zabbixとうまく組み合わせて可視化してみると楽しいかも
● 使ってみてちょっと気になった点
○ apache ログをmongoDBに格納する際に少しタイムラグあり?→Bufferのレイヤの挙動を今後確認予定