fluentd 0.10.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of fluentd might be problematic. Click here for more details.

Files changed (54) hide show
  1. data/AUTHORS +1 -0
  2. data/COPYING +14 -0
  3. data/ChangeLog +178 -0
  4. data/README.rdoc +57 -0
  5. data/Rakefile +62 -0
  6. data/VERSION +1 -0
  7. data/bin/fluent-cat +6 -0
  8. data/bin/fluent-gem +10 -0
  9. data/bin/fluentd +6 -0
  10. data/fluent.conf +78 -0
  11. data/fluentd.gemspec +116 -0
  12. data/lib/fluent/buffer.rb +274 -0
  13. data/lib/fluent/command/cat.rb +299 -0
  14. data/lib/fluent/command/fluentd.rb +245 -0
  15. data/lib/fluent/config.rb +304 -0
  16. data/lib/fluent/engine.rb +224 -0
  17. data/lib/fluent/env.rb +6 -0
  18. data/lib/fluent/event.rb +159 -0
  19. data/lib/fluent/input.rb +41 -0
  20. data/lib/fluent/load.rb +23 -0
  21. data/lib/fluent/log.rb +277 -0
  22. data/lib/fluent/match.rb +189 -0
  23. data/lib/fluent/mixin.rb +170 -0
  24. data/lib/fluent/output.rb +466 -0
  25. data/lib/fluent/parser.rb +115 -0
  26. data/lib/fluent/plugin.rb +145 -0
  27. data/lib/fluent/plugin/buf_file.rb +181 -0
  28. data/lib/fluent/plugin/buf_memory.rb +97 -0
  29. data/lib/fluent/plugin/buf_zfile.rb +84 -0
  30. data/lib/fluent/plugin/in_http.rb +282 -0
  31. data/lib/fluent/plugin/in_stream.rb +187 -0
  32. data/lib/fluent/plugin/in_syslog.rb +174 -0
  33. data/lib/fluent/plugin/in_tail.rb +150 -0
  34. data/lib/fluent/plugin/out_copy.rb +72 -0
  35. data/lib/fluent/plugin/out_file.rb +111 -0
  36. data/lib/fluent/plugin/out_null.rb +44 -0
  37. data/lib/fluent/plugin/out_roundrobin.rb +72 -0
  38. data/lib/fluent/plugin/out_stdout.rb +34 -0
  39. data/lib/fluent/plugin/out_stream.rb +128 -0
  40. data/lib/fluent/plugin/out_test.rb +68 -0
  41. data/lib/fluent/test.rb +8 -0
  42. data/lib/fluent/test/base.rb +63 -0
  43. data/lib/fluent/test/input_test.rb +89 -0
  44. data/lib/fluent/test/output_test.rb +93 -0
  45. data/lib/fluent/version.rb +5 -0
  46. data/test/helper.rb +6 -0
  47. data/test/match.rb +115 -0
  48. data/test/plugin/in_http.rb +84 -0
  49. data/test/plugin/in_stream.rb +136 -0
  50. data/test/plugin/out_copy.rb +55 -0
  51. data/test/plugin/out_file.rb +82 -0
  52. data/test/plugin/out_roundrobin.rb +65 -0
  53. data/test/plugin/out_stream.rb +74 -0
  54. metadata +224 -0
@@ -0,0 +1,44 @@
1
+ #
2
+ # Fluent
3
+ #
4
+ # Copyright (C) 2011 FURUHASHI Sadayuki
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ module Fluent
19
+
20
+
21
+ class NullOutput < Output
22
+ Plugin.register_output('null', self)
23
+
24
+ def initialize
25
+ super
26
+ end
27
+
28
+ def configure(conf)
29
+ super
30
+ end
31
+
32
+ def start
33
+ end
34
+
35
+ def shutdown
36
+ end
37
+
38
+ def emit(tag, es, chain)
39
+ chain.next
40
+ end
41
+ end
42
+
43
+
44
+ end
@@ -0,0 +1,72 @@
1
+ #
2
+ # Fluent
3
+ #
4
+ # Copyright (C) 2011 FURUHASHI Sadayuki
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ module Fluent
19
+
20
+
21
+ class RoundRobinOutput < MultiOutput
22
+ Plugin.register_output('roundrobin', self)
23
+
24
+ def initialize
25
+ @outputs = []
26
+ end
27
+
28
+ attr_reader :outputs
29
+
30
+ def configure(conf)
31
+ conf.elements.select {|e|
32
+ e.name == 'store'
33
+ }.each {|e|
34
+ type = e['type']
35
+ unless type
36
+ raise ConfigError, "Missing 'type' parameter on <store> directive"
37
+ end
38
+ $log.debug "adding store type=#{type.dump}"
39
+
40
+ output = Plugin.new_output(type)
41
+ output.configure(e)
42
+ @outputs << output
43
+ }
44
+ @rr = -1 # starts from @output[0]
45
+ end
46
+
47
+ def start
48
+ @outputs.each {|o|
49
+ o.start
50
+ }
51
+ end
52
+
53
+ def shutdown
54
+ @outputs.each {|o|
55
+ o.shutdown
56
+ }
57
+ end
58
+
59
+ def emit(tag, es, chain)
60
+ next_output.emit(tag, es, chain)
61
+ end
62
+
63
+ protected
64
+ def next_output
65
+ @rr = 0 if (@rr += 1) >= @outputs.size
66
+ @outputs[@rr]
67
+ end
68
+ end
69
+
70
+
71
+ end
72
+
@@ -0,0 +1,34 @@
1
+ #
2
+ # Fluent
3
+ #
4
+ # Copyright (C) 2011 FURUHASHI Sadayuki
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ module Fluent
19
+
20
+
21
+ class StdoutOutput < Output
22
+ Plugin.register_output('stdout', self)
23
+
24
+ def emit(tag, es, chain)
25
+ es.each {|time,record|
26
+ puts "#{Time.at(time).localtime} #{tag}: #{record.to_json}"
27
+ }
28
+ chain.next
29
+ end
30
+ end
31
+
32
+
33
+ end
34
+
@@ -0,0 +1,128 @@
1
+ #
2
+ # Fluent
3
+ #
4
+ # Copyright (C) 2011 FURUHASHI Sadayuki
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ module Fluent
19
+
20
+
21
+ class StreamOutput < BufferedOutput
22
+ def initialize
23
+ super
24
+ require 'socket'
25
+ require 'fileutils'
26
+ @send_timeout = 60
27
+ end
28
+
29
+ config_param :send_timeout, :time, :default => 60
30
+
31
+ def configure(conf)
32
+ super
33
+ end
34
+
35
+ def format_stream(tag, es)
36
+ # use PackedForward
37
+ [tag, es.to_msgpack_stream].to_msgpack
38
+ end
39
+
40
+ def write(chunk)
41
+ sock = connect
42
+ begin
43
+ opt = [1, @send_timeout.to_i].pack('I!I!') # { int l_onoff; int l_linger; }
44
+ sock.setsockopt(Socket::SOL_SOCKET, Socket::SO_LINGER, opt)
45
+
46
+ opt = [@send_timeout.to_i, 0].pack('L!L!') # struct timeval
47
+ sock.setsockopt(Socket::SOL_SOCKET, Socket::SO_SNDTIMEO, opt)
48
+
49
+ chunk.write_to(sock)
50
+ ensure
51
+ sock.close
52
+ end
53
+ end
54
+
55
+ def flush_secondary(secondary)
56
+ unless secondary.is_a?(StreamOutput)
57
+ secondary = ReformatWriter.new(secondary)
58
+ end
59
+ @buffer.pop(secondary)
60
+ end
61
+
62
+ class ReformatWriter
63
+ def initialize(secondary)
64
+ @secondary = secondary
65
+ end
66
+
67
+ def write(chunk)
68
+ chain = NullOutputChain.instance
69
+ chunk.open {|io|
70
+ # TODO use MessagePackIoEventStream
71
+ u = MessagePack::Unpacker.new(io)
72
+ begin
73
+ u.each {|(tag,entries)|
74
+ es = MultiEventStream.new
75
+ entries.each {|o|
76
+ es.add(o[0], o[1])
77
+ }
78
+ @secondary.emit(tag, es, chain)
79
+ }
80
+ rescue EOFError
81
+ end
82
+ }
83
+ end
84
+ end
85
+ end
86
+
87
+
88
+ class TcpOutput < StreamOutput
89
+ Plugin.register_output('tcp', self)
90
+
91
+ def initialize
92
+ super
93
+ end
94
+
95
+ config_param :port, :integer, :default => DEFAULT_LISTEN_PORT
96
+ config_param :host, :string
97
+
98
+ def configure(conf)
99
+ super
100
+ end
101
+
102
+ def connect
103
+ TCPSocket.new(@host, @port)
104
+ end
105
+ end
106
+
107
+
108
+ class UnixOutput < StreamOutput
109
+ Plugin.register_output('unix', self)
110
+
111
+ def initialize
112
+ super
113
+ end
114
+
115
+ config_param :path, :string
116
+
117
+ def configure(conf)
118
+ super
119
+ end
120
+
121
+ def connect
122
+ UNIXSocket.new(@path)
123
+ end
124
+ end
125
+
126
+
127
+ end
128
+
@@ -0,0 +1,68 @@
1
+ #
2
+ # Fluent
3
+ #
4
+ # Copyright (C) 2011 FURUHASHI Sadayuki
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ module Fluent
19
+
20
+
21
+ class TestOutput < Output
22
+ Plugin.register_output('test', self)
23
+
24
+ def initialize
25
+ @emits = []
26
+ @name = nil
27
+ end
28
+
29
+ attr_reader :emits, :name
30
+
31
+ def events
32
+ all = []
33
+ @emits.each {|tag,events|
34
+ all.concat events
35
+ }
36
+ all
37
+ end
38
+
39
+ def records
40
+ all = []
41
+ @emits.each {|tag,events|
42
+ events.each {|time,record|
43
+ all << record
44
+ }
45
+ }
46
+ all
47
+ end
48
+
49
+ def configure(conf)
50
+ if name = conf['name']
51
+ @name = name
52
+ end
53
+ end
54
+
55
+ def start
56
+ end
57
+
58
+ def shutdown
59
+ end
60
+
61
+ def emit(tag, es, chain)
62
+ chain.next
63
+ @emits << [tag, es.to_a]
64
+ end
65
+ end
66
+
67
+
68
+ end
@@ -0,0 +1,8 @@
1
+ require 'test/unit'
2
+ require 'fluent/load'
3
+ require 'fluent/test/base'
4
+ require 'fluent/test/input_test'
5
+ require 'fluent/test/output_test'
6
+
7
+ $log ||= Fluent::Log.new
8
+
@@ -0,0 +1,63 @@
1
+ #
2
+ # Fluent
3
+ #
4
+ # Copyright (C) 2011 FURUHASHI Sadayuki
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ module Fluent
19
+ module Test
20
+
21
+
22
+ class TestDriver
23
+ include ::Test::Unit::Assertions
24
+
25
+ def initialize(klass, &block)
26
+ if klass.is_a?(Class)
27
+ if block
28
+ klass = Class.new(klass, &block)
29
+ end
30
+ @instance = klass.new
31
+ else
32
+ @instance = klass
33
+ end
34
+ @config = Config.new
35
+ end
36
+
37
+ attr_reader :instance, :config
38
+
39
+ def configure(str)
40
+ if str.is_a?(Config)
41
+ @config = @str
42
+ else
43
+ @config = Config.parse(str, "(test)")
44
+ end
45
+ @instance.configure(@config)
46
+ self
47
+ end
48
+
49
+ def run(&block)
50
+ @instance.start
51
+ begin
52
+ # wait until thread starts
53
+ 10.times { sleep 0.01 }
54
+ return yield
55
+ ensure
56
+ @instance.shutdown
57
+ end
58
+ end
59
+ end
60
+
61
+
62
+ end
63
+ end
@@ -0,0 +1,89 @@
1
+ #
2
+ # Fluent
3
+ #
4
+ # Copyright (C) 2011 FURUHASHI Sadayuki
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ module Fluent
19
+ module Test
20
+
21
+
22
+ class InputTestDriver < TestDriver
23
+ def initialize(klass, &block)
24
+ super(klass, &block)
25
+ @emits = []
26
+ @expects = nil
27
+ end
28
+
29
+ def expect_emit(tag, time, record)
30
+ (@expects ||= []) << [tag, time, record]
31
+ self
32
+ end
33
+
34
+ def expected_emits
35
+ @expects ||= []
36
+ end
37
+
38
+ attr_reader :emits
39
+
40
+ def events
41
+ all = []
42
+ @emits.each {|tag,events|
43
+ all.concat events
44
+ }
45
+ all
46
+ end
47
+
48
+ def records
49
+ all = []
50
+ @emits.each {|tag,events|
51
+ events.each {|time,record|
52
+ all << record
53
+ }
54
+ }
55
+ all
56
+ end
57
+
58
+ def run(&block)
59
+ m = method(:emit_stream)
60
+ super {
61
+ Engine.define_singleton_method(:emit_stream) {|tag,es|
62
+ m.call(tag, es)
63
+ }
64
+
65
+ block.call if block
66
+
67
+ if @expects
68
+ i = 0
69
+ @emits.each {|tag,events|
70
+ events.each {|time,record|
71
+ assert_equal(@expects[i], [tag, time, record])
72
+ i += 1
73
+ }
74
+ }
75
+ assert_equal @expects.length, i
76
+ end
77
+ }
78
+ self
79
+ end
80
+
81
+ private
82
+ def emit_stream(tag, es)
83
+ @emits << [tag, es.to_a]
84
+ end
85
+ end
86
+
87
+
88
+ end
89
+ end