1、轉儲到單個文件的配置
<source>
type tail
path /home/aircom/mongodb-linux-i686-2.0.6/bin/logs/1001.log
format /^*(?<message>.*)$/
tag mongo.apache
</source>
<source>
type tail
path /home/aircom/mongodb-linux-i686-2.0.6/bin/logs/1002.log
format /^*(?<message>.*)$/
tag mongo.apache
</source>
匹配的時候第一個mongo.apache結果生效,所以如下轉儲到mongodb會生效,後面的轉儲到文件不會生效,因此如下的配置已經註釋掉了,爲的是讓後面的轉儲文件生效。
#<match mongo.**>
# type mongo
# database apache
# collection fmongo
# host Server202
# port 10001
# flush_interval 1s
#</match>
<match mongo.**>
type filepath /var/log/fluent/access
</match>
到目錄下驗證轉儲效果
[root@Server202 fluent]# pwd
/var/log/fluent
[root@Server202 fluent]# ll
total 64
-rw-rw-rw- 1 root root 57824 Sep 27 14:06 access.20120927.b4caa87ded0f11576
有一個文件access.20120927.b4caa87ded0f11576
tail這個文件,可以看到日誌在不斷變化着
tail -f access.20120927.b4caa87ded0f11576
2012-09-27T14:07:14+08:00 mongo.apache {"message":"Thu Sep 27 14:07:14 [conn10450] end connection 192.168.19.202:42236"}
2012-09-27T14:07:14+08:00 mongo.apache {"message":"Thu Sep 27 14:07:14 [initandlisten] connection accepted from 192.168.19.
2、轉儲到多個文件的配置
<match mongo.**>
type copy
<store>
type file
path /var/log/fluent/access
</store>
<store>
type file
path /var/log/fluent/bccess
</store>
</match>
copy指定多個輸出
store規則與match相同
驗證結果:
[root@Server202 fluent]# ll
total 184
-rw-rw-rw- 1 root root 165074 Sep 27 15:20 access.20120927.b4caa87ded0f11576
-rw-rw-rw- 1 root root 16034 Sep 27 15:20 bccess.20120927.b4caa9b5665aeb9b4
有2個轉儲後的文件分別爲access.20120927.b4caa87ded0f11576 和 bccess.20120927.b4caa9b5665aeb9b4
分別tail 會看到相同的日誌輸出
tail -f access.20120927.b4caa87ded0f11576
2012-09-27T15:22:20+08:00 mongo.apache {"message":"Thu Sep 27 15:22:20 [conn10831] end connection 192.168.19.201:54006"}
2012-09-27T15:22:20+08:00 mongo.apache {"message":"Thu Sep 27 15:22:20 [initandlisten] connection accepted from 192.168.19.201:54012 #10834"}
tail -f bccess.20120927.b4caa9b5665aeb9b4
2012-09-27T15:22:20+08:00 mongo.apache {"message":"Thu Sep 27 15:22:20 [conn10831] end connection 192.168.19.201:54006"}
2012-09-27T15:22:20+08:00 mongo.apache {"message":"Thu Sep 27 15:22:20 [initandlisten] connection accepted from 192.168.19.201:54012 #10834"}
3、轉儲到2個文件,一個mongodb的配置。
<match mongo.**>
type copy
<store>
type file
path /var/log/fluent/access
</store>
<store>
type file
path /var/log/fluent/bccess
</store>
<store>
type mongo
database apache
collection fmongo
host Server202
port 10001
flush_interval 1s
</store>
</match>