fluentからMongoDBのドキュメント挿入方法 #fluent

Webサーバからfluent-plugin-mongoを使って、
以下の流れでApacheアクセスログをMongoDBに突っ込むことができたのでメモ。

 Webサーバ → fluentサーバ → MongoDBサーバ

【サーバ構成】
サーバ構成の詳細は、以下のとおり。

■Webサーバ
  OS:CentOS 5.6
  fluent:0.9.19
  Apache:2.2.3
■fluentサーバ
  OS:CentOS 6.0
  fluent:0.9.19
  fluent-plugin-mongo:0.3.1
■MongoDBサーバ
  OS:CentOS6.0
  MongoDB:2.0.0

【各設定ファイル】
Webサーバとfluentサーバのfluentの設定ファイルは、以下の内容。
#もっとよい記述方法があるかも

■Webサーバ


 type tail
 format apache
 time_format %d/%b/%Y:%H:%M:%S %z
 path /var/log/httpd/access_log
 tag mongo

 type tcp
 host 【fluentサーバのホスト名】
 port 24224
 buffer_type file
 buffer_path /tmp/fluent_buf_mongo
 flush_interval 10s

■fluentサーバ


 type tcp
 port 24224
 bind 0.0.0.0

 type mongo
 database 【mongodbサーバのデータベース名】
 collection 【mongodbサーバのコレクション名】
 host 【fluentサーバのホスト名】
 port 27017

【確認方法】

1.WebサーバのApache立ち上げ
 /etc/init.d/httpd start
2.Webサーバのfluent立ち上げ(トレースモードで起動)
 fluentd -c /etc/fluent/fluent.conf -vv
3.fluentサーバのfluent立ち上げ(トレースモードで起動)
 fluentd -c /etc/fluent/fluent.conf -vv
4.MongoDBサーバのMongoDB立ち上げ
 /etc/init.d/mongod
5.ブラウザを使って、WebサーバのApacheにアクセス

【結果】
mongodbに接続し、ドキュメントが挿入されていることを確認
#当然、ドキュメントの中身も確認できる

> db.test.count()
55
> db.test.count()
59

【やってみて感じたこと】
■MongoDBに挿入された後のドキュメントに、timeのカラムがない?
 → fluentのドキュメントを見てみると、time_formatを使えばできそうな気はするけどまだ未確認()
※[2011/11/17 追記]fluent0.10.1からtimeフィールドが入るようになりました。

fluent触ってて楽しいので、また共有できる内容があればブログ更新します。