Skip to content

Instantly share code, notes, and snippets.

@oza
Created March 1, 2012 14:32
Show Gist options
  • Save oza/1950170 to your computer and use it in GitHub Desktop.
Save oza/1950170 to your computer and use it in GitHub Desktop.
The sample source code of user-defined filter for fluentd
ozawa@ozamba:~/workspace/fluent/fluentd/com/lib/fluent$ ../../bin/fluentd -c ../../fluent.conf
2012-03-01 23:15:18 +0900: starting fluentd-0.10.13
2012-03-01 23:15:18 +0900: reading config file path="../../fluent.conf"
2012-03-01 23:15:18 +0900: adding source type="forward"
2012-03-01 23:15:18 +0900: adding source type="http"
2012-03-01 23:15:18 +0900: adding source type="tail"
2012-03-01 23:15:18 +0900: sample
2012-03-01 23:15:18 +0900: /Users/ozawa/size_limit.rb
2012-03-01 23:15:18 +0900: adding match pattern="debug.**" type="stdout"
2012-03-01 23:15:18 +0900: listening fluent socket on 0.0.0.0:24224
2012-03-01 23:15:18 +0900: following tail of /var/log/apache2/access_log
1330611321{"host"=>"::1", "user"=>"-", "method"=>"GET", "path"=>"/", "code"=>"404", "size"=>"277"}
1330611321{"host"=>"::1", "user"=>"-", "method"=>"GET", "path"=>"/favicon.ico", "code"=>"404", "size"=>"288"}
1330611321{"host"=>"::1", "user"=>"-", "method"=>"GET", "path"=>"/", "code"=>"404", "size"=>"277"}
1330611321{"host"=>"::1", "user"=>"-", "method"=>"GET", "path"=>"/favicon.ico", "code"=>"404", "size"=>"288"}
1330611321{"host"=>"::1", "user"=>"-", "method"=>"GET", "path"=>"/", "code"=>"404", "size"=>"277"}
1330611321{"host"=>"::1", "user"=>"-", "method"=>"GET", "path"=>"/favicon.ico", "code"=>"404", "size"=>"288"}
1330611321{"host"=>"::1", "user"=>"-", "method"=>"GET", "path"=>"/", "code"=>"404", "size"=>"277"}
1330611321{"host"=>"::1", "user"=>"-", "method"=>"GET", "path"=>"/favicon.ico", "code"=>"404", "size"=>"288"}
1330611322{"host"=>"::1", "user"=>"-", "method"=>"GET", "path"=>"/", "code"=>"404", "size"=>"277"}
1330611322{"host"=>"::1", "user"=>"-", "method"=>"GET", "path"=>"/favicon.ico", "code"=>"404", "size"=>"288"}
2012-03-01 23:15:22 +0900: no patterns matched tag="apache.access"
1330611322{"host"=>"::1", "user"=>"-", "method"=>"GET", "path"=>"/", "code"=>"404", "size"=>"277"}
1330611322{"host"=>"::1", "user"=>"-", "method"=>"GET", "path"=>"/favicon.ico", "code"=>"404", "size"=>"288"}
2012-03-01 23:15:23 +0900: no patterns matched tag="apache.access"
^C2012-03-01 23:18:28 +0900: shutting down fluentd
2012-03-01 23:18:28 +0900: shutting down fluentd
2012-03-01 23:18:29 +0900: process finished code=0
<source>
type tail
pos_file /Users/ozawa/pos
format apache
path /var/log/apache2/access_log
tag apache.access
filter_type sample
filter_script /Users/ozawa/size_limit.rb
</source>
module Fluent
class SampleFilter < Filter
Fluent::Plugin.register_filter('sample', self)
def filter(time, record)
puts time.to_s + record.to_s
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment