fluentd 0.10.35 → 0.10.36

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.

@@ -16,42 +16,38 @@
16
16
  # limitations under the License.
17
17
  #
18
18
  module Fluent
19
+ class DebugAgentInput < Input
20
+ Plugin.register_input('debug_agent', self)
19
21
 
22
+ def initialize
23
+ require 'drb/drb'
24
+ super
25
+ end
20
26
 
21
- class DebugAgentInput < Input
22
- Plugin.register_input('debug_agent', self)
23
-
24
- def initialize
25
- require 'drb/drb'
26
- super
27
- end
28
-
29
- config_param :bind, :string, :default => '0.0.0.0'
30
- config_param :port, :integer, :default => 24230
31
- config_param :unix_path, :integer, :default => nil
32
- #config_param :unix_mode # TODO
33
- config_param :object, :string, :default => 'Engine'
27
+ config_param :bind, :string, :default => '0.0.0.0'
28
+ config_param :port, :integer, :default => 24230
29
+ config_param :unix_path, :integer, :default => nil
30
+ #config_param :unix_mode # TODO
31
+ config_param :object, :string, :default => 'Engine'
34
32
 
35
- def configure(conf)
36
- super
37
- end
33
+ def configure(conf)
34
+ super
35
+ end
38
36
 
39
- def start
40
- if @unix_path
41
- require 'drb/unix'
42
- uri = "drbunix:#{@unix_path}"
43
- else
44
- uri = "druby://#{@bind}:#{@port}"
37
+ def start
38
+ if @unix_path
39
+ require 'drb/unix'
40
+ uri = "drbunix:#{@unix_path}"
41
+ else
42
+ uri = "druby://#{@bind}:#{@port}"
43
+ end
44
+ $log.info "listening dRuby", :uri => uri, :object => @object
45
+ obj = eval(@object)
46
+ @server = DRb::DRbServer.new(uri, obj)
45
47
  end
46
- $log.info "listening dRuby", :uri => uri, :object => @object
47
- obj = eval(@object)
48
- @server = DRb::DRbServer.new(uri, obj)
49
- end
50
48
 
51
- def shutdown
52
- @server.stop_service if @server
49
+ def shutdown
50
+ @server.stop_service if @server
51
+ end
53
52
  end
54
53
  end
55
-
56
-
57
- end
@@ -16,117 +16,113 @@
16
16
  # limitations under the License.
17
17
  #
18
18
  module Fluent
19
+ class ExecInput < Input
20
+ Plugin.register_input('exec', self)
19
21
 
22
+ def initialize
23
+ super
24
+ end
20
25
 
21
- class ExecInput < Input
22
- Plugin.register_input('exec', self)
23
-
24
- def initialize
25
- super
26
- end
26
+ config_param :command, :string
27
+ config_param :keys, :string
28
+ config_param :tag, :string, :default => nil
29
+ config_param :tag_key, :string, :default => nil
30
+ config_param :time_key, :string, :default => nil
31
+ config_param :time_format, :string, :default => nil
32
+ config_param :run_interval, :time, :default => nil
33
+
34
+ def configure(conf)
35
+ super
36
+
37
+ if localtime = conf['localtime']
38
+ @localtime = true
39
+ elsif utc = conf['utc']
40
+ @localtime = false
41
+ end
27
42
 
28
- config_param :command, :string
29
- config_param :keys, :string
30
- config_param :tag, :string, :default => nil
31
- config_param :tag_key, :string, :default => nil
32
- config_param :time_key, :string, :default => nil
33
- config_param :time_format, :string, :default => nil
34
- config_param :run_interval, :time, :default => nil
43
+ if !@tag && !@tag_key
44
+ raise ConfigError, "'tag' or 'tag_key' option is required on exec input"
45
+ end
35
46
 
36
- def configure(conf)
37
- super
47
+ @keys = @keys.split(',')
38
48
 
39
- if localtime = conf['localtime']
40
- @localtime = true
41
- elsif utc = conf['utc']
42
- @localtime = false
49
+ if @time_key
50
+ if @time_format
51
+ f = @time_format
52
+ @time_parse_proc = Proc.new {|str| Time.strptime(str, f).to_i }
53
+ else
54
+ @time_parse_proc = Proc.new {|str| str.to_i }
55
+ end
56
+ end
43
57
  end
44
58
 
45
- if !@tag && !@tag_key
46
- raise ConfigError, "'tag' or 'tag_key' option is required on exec input"
59
+ def start
60
+ if @run_interval
61
+ @finished = false
62
+ @thread = Thread.new(&method(:run_periodic))
63
+ else
64
+ @io = IO.popen(@command, "r")
65
+ @pid = @io.pid
66
+ @thread = Thread.new(&method(:run))
67
+ end
47
68
  end
48
69
 
49
- @keys = @keys.split(',')
50
-
51
- if @time_key
52
- if @time_format
53
- f = @time_format
54
- @time_parse_proc = Proc.new {|str| Time.strptime(str, f).to_i }
70
+ def shutdown
71
+ if @run_interval
72
+ @finished = true
73
+ @thread.join
55
74
  else
56
- @time_parse_proc = Proc.new {|str| str.to_i }
75
+ Process.kill(:TERM, @pid)
76
+ if @thread.join(60) # TODO wait time
77
+ return
78
+ end
79
+ Process.kill(:KILL, @pid)
80
+ @thread.join
57
81
  end
58
82
  end
59
- end
60
83
 
61
- def start
62
- if @run_interval
63
- @finished = false
64
- @thread = Thread.new(&method(:run_periodic))
65
- else
66
- @io = IO.popen(@command, "r")
67
- @pid = @io.pid
68
- @thread = Thread.new(&method(:run))
84
+ def run
85
+ @io.each_line(&method(:each_line))
69
86
  end
70
- end
71
87
 
72
- def shutdown
73
- if @run_interval
74
- @finished = true
75
- @thread.join
76
- else
77
- Process.kill(:TERM, @pid)
78
- if @thread.join(60) # TODO wait time
79
- return
88
+ def run_periodic
89
+ until @finished
90
+ sleep @run_interval
91
+ io = IO.popen(@command, "r")
92
+ io.each_line(&method(:each_line))
93
+ Process.waitpid(io.pid)
80
94
  end
81
- Process.kill(:KILL, @pid)
82
- @thread.join
83
95
  end
84
- end
85
-
86
- def run
87
- @io.each_line(&method(:each_line))
88
- end
89
-
90
- def run_periodic
91
- until @finished
92
- sleep @run_interval
93
- io = IO.popen(@command, "r")
94
- io.each_line(&method(:each_line))
95
- Process.waitpid(io.pid)
96
- end
97
- end
98
-
99
- private
100
- def each_line(line)
101
- begin
102
- line.chomp!
103
- vals = line.split("\t")
104
96
 
105
- tag = @tag
106
- time = nil
107
- record = {}
108
- for i in 0..@keys.length-1
109
- key = @keys[i]
110
- val = vals[i]
111
- if key == @time_key
112
- time = @time_parse_proc.call(val)
113
- elsif key == @tag_key
114
- tag = val
115
- else
116
- record[key] = val
97
+ private
98
+ def each_line(line)
99
+ begin
100
+ line.chomp!
101
+ vals = line.split("\t")
102
+
103
+ tag = @tag
104
+ time = nil
105
+ record = {}
106
+ for i in 0..@keys.length-1
107
+ key = @keys[i]
108
+ val = vals[i]
109
+ if key == @time_key
110
+ time = @time_parse_proc.call(val)
111
+ elsif key == @tag_key
112
+ tag = val
113
+ else
114
+ record[key] = val
115
+ end
117
116
  end
118
- end
119
117
 
120
- if tag
121
- time ||= Engine.now
122
- Engine.emit(tag, time, record)
118
+ if tag
119
+ time ||= Engine.now
120
+ Engine.emit(tag, time, record)
121
+ end
122
+ rescue
123
+ $log.error "exec failed to emit", :error=>$!.to_s, :line=>line
124
+ $log.warn_backtrace $!.backtrace
123
125
  end
124
- rescue
125
- $log.error "exec failed to emit", :error=>$!.to_s, :line=>line
126
- $log.warn_backtrace $!.backtrace
127
126
  end
128
127
  end
129
128
  end
130
-
131
-
132
- end
@@ -18,207 +18,207 @@
18
18
  module Fluent
19
19
 
20
20
 
21
- class ForwardInput < Input
22
- Plugin.register_input('forward', self)
21
+ class ForwardInput < Input
22
+ Plugin.register_input('forward', self)
23
23
 
24
- def initialize
25
- super
26
- require 'fluent/plugin/socket_util'
27
- end
28
-
29
- config_param :port, :integer, :default => DEFAULT_LISTEN_PORT
30
- config_param :bind, :string, :default => '0.0.0.0'
31
-
32
- def configure(conf)
33
- super
34
- end
24
+ def initialize
25
+ super
26
+ require 'fluent/plugin/socket_util'
27
+ end
35
28
 
36
- def start
37
- @loop = Coolio::Loop.new
29
+ config_param :port, :integer, :default => DEFAULT_LISTEN_PORT
30
+ config_param :bind, :string, :default => '0.0.0.0'
31
+ config_param :backlog, :integer, :default => nil
38
32
 
39
- @lsock = listen
40
- @loop.attach(@lsock)
33
+ def configure(conf)
34
+ super
35
+ end
41
36
 
42
- @usock = SocketUtil.create_udp_socket(@bind)
43
- @usock.bind(@bind, @port)
44
- @usock.fcntl(Fcntl::F_SETFL, Fcntl::O_NONBLOCK)
45
- @hbr = HeartbeatRequestHandler.new(@usock, method(:on_heartbeat_request))
46
- @loop.attach(@hbr)
37
+ def start
38
+ @loop = Coolio::Loop.new
47
39
 
48
- @thread = Thread.new(&method(:run))
49
- @cached_unpacker = $use_msgpack_5 ? nil : MessagePack::Unpacker.new
50
- end
40
+ @lsock = listen
41
+ @loop.attach(@lsock)
51
42
 
52
- def shutdown
53
- @loop.watchers.each {|w| w.detach }
54
- @loop.stop
55
- @usock.close
56
- listen_address = (@bind == '0.0.0.0' ? '127.0.0.1' : @bind)
57
- TCPSocket.open(listen_address, @port) {|sock| } # FIXME @thread.join blocks without this line
58
- @thread.join
59
- @lsock.close
60
- end
43
+ @usock = SocketUtil.create_udp_socket(@bind)
44
+ @usock.bind(@bind, @port)
45
+ @usock.fcntl(Fcntl::F_SETFL, Fcntl::O_NONBLOCK)
46
+ @hbr = HeartbeatRequestHandler.new(@usock, method(:on_heartbeat_request))
47
+ @loop.attach(@hbr)
61
48
 
62
- def listen
63
- $log.info "listening fluent socket on #{@bind}:#{@port}"
64
- Coolio::TCPServer.new(@bind, @port, Handler, method(:on_message))
65
- end
49
+ @thread = Thread.new(&method(:run))
50
+ @cached_unpacker = $use_msgpack_5 ? nil : MessagePack::Unpacker.new
51
+ end
66
52
 
67
- #config_param :path, :string, :default => DEFAULT_SOCKET_PATH
68
- #def listen
69
- # if File.exist?(@path)
70
- # File.unlink(@path)
71
- # end
72
- # FileUtils.mkdir_p File.dirname(@path)
73
- # $log.debug "listening fluent socket on #{@path}"
74
- # Coolio::UNIXServer.new(@path, Handler, method(:on_message))
75
- #end
76
-
77
- def run
78
- @loop.run
79
- rescue
80
- $log.error "unexpected error", :error=>$!.to_s
81
- $log.error_backtrace
82
- end
53
+ def shutdown
54
+ @loop.watchers.each {|w| w.detach }
55
+ @loop.stop
56
+ @usock.close
57
+ listen_address = (@bind == '0.0.0.0' ? '127.0.0.1' : @bind)
58
+ TCPSocket.open(listen_address, @port) {|sock| } # FIXME @thread.join blocks without this line
59
+ @thread.join
60
+ @lsock.close
61
+ end
83
62
 
84
- protected
85
- # message Entry {
86
- # 1: long time
87
- # 2: object record
88
- # }
89
- #
90
- # message Forward {
91
- # 1: string tag
92
- # 2: list<Entry> entries
93
- # }
94
- #
95
- # message PackedForward {
96
- # 1: string tag
97
- # 2: raw entries # msgpack stream of Entry
98
- # }
99
- #
100
- # message Message {
101
- # 1: string tag
102
- # 2: long? time
103
- # 3: object record
104
- # }
105
- def on_message(msg)
106
- if msg.nil?
107
- # for future TCP heartbeat_request
108
- return
63
+ def listen
64
+ $log.info "listening fluent socket on #{@bind}:#{@port}"
65
+ s = Coolio::TCPServer.new(@bind, @port, Handler, method(:on_message))
66
+ s.listen(@backlog) unless @backlog.nil?
67
+ s
109
68
  end
110
69
 
111
- # TODO format error
112
- tag = msg[0].to_s
113
- entries = msg[1]
114
-
115
- if entries.class == String
116
- # PackedForward
117
- es = MessagePackEventStream.new(entries, @cached_unpacker)
118
- Engine.emit_stream(tag, es)
119
-
120
- elsif entries.class == Array
121
- # Forward
122
- es = MultiEventStream.new
123
- entries.each {|e|
124
- time = e[0].to_i
125
- time = (now ||= Engine.now) if time == 0
126
- record = e[1]
127
- es.add(time, record)
128
- }
129
- Engine.emit_stream(tag, es)
130
-
131
- else
132
- # Message
133
- time = msg[1]
134
- time = Engine.now if time == 0
135
- record = msg[2]
136
- Engine.emit(tag, time, record)
70
+ #config_param :path, :string, :default => DEFAULT_SOCKET_PATH
71
+ #def listen
72
+ # if File.exist?(@path)
73
+ # File.unlink(@path)
74
+ # end
75
+ # FileUtils.mkdir_p File.dirname(@path)
76
+ # $log.debug "listening fluent socket on #{@path}"
77
+ # Coolio::UNIXServer.new(@path, Handler, method(:on_message))
78
+ #end
79
+
80
+ def run
81
+ @loop.run
82
+ rescue
83
+ $log.error "unexpected error", :error=>$!.to_s
84
+ $log.error_backtrace
137
85
  end
138
- end
139
86
 
140
- class Handler < Coolio::Socket
141
- def initialize(io, on_message)
142
- super(io)
143
- if io.is_a?(TCPSocket)
144
- opt = [1, @timeout.to_i].pack('I!I!') # { int l_onoff; int l_linger; }
145
- io.setsockopt(Socket::SOL_SOCKET, Socket::SO_LINGER, opt)
87
+ protected
88
+ # message Entry {
89
+ # 1: long time
90
+ # 2: object record
91
+ # }
92
+ #
93
+ # message Forward {
94
+ # 1: string tag
95
+ # 2: list<Entry> entries
96
+ # }
97
+ #
98
+ # message PackedForward {
99
+ # 1: string tag
100
+ # 2: raw entries # msgpack stream of Entry
101
+ # }
102
+ #
103
+ # message Message {
104
+ # 1: string tag
105
+ # 2: long? time
106
+ # 3: object record
107
+ # }
108
+ def on_message(msg)
109
+ if msg.nil?
110
+ # for future TCP heartbeat_request
111
+ return
146
112
  end
147
- $log.trace { "accepted fluent socket object_id=#{self.object_id}" }
148
- @on_message = on_message
149
- end
150
113
 
151
- def on_connect
152
- end
114
+ # TODO format error
115
+ tag = msg[0].to_s
116
+ entries = msg[1]
117
+
118
+ if entries.class == String
119
+ # PackedForward
120
+ es = MessagePackEventStream.new(entries, @cached_unpacker)
121
+ Engine.emit_stream(tag, es)
122
+
123
+ elsif entries.class == Array
124
+ # Forward
125
+ es = MultiEventStream.new
126
+ entries.each {|e|
127
+ time = e[0].to_i
128
+ time = (now ||= Engine.now) if time == 0
129
+ record = e[1]
130
+ es.add(time, record)
131
+ }
132
+ Engine.emit_stream(tag, es)
153
133
 
154
- def on_read(data)
155
- first = data[0]
156
- if first == '{' || first == '['
157
- m = method(:on_read_json)
158
- @y = Yajl::Parser.new
159
- @y.on_parse_complete = @on_message
160
134
  else
161
- m = method(:on_read_msgpack)
162
- @u = MessagePack::Unpacker.new
135
+ # Message
136
+ time = msg[1]
137
+ time = Engine.now if time == 0
138
+ record = msg[2]
139
+ Engine.emit(tag, time, record)
163
140
  end
141
+ end
164
142
 
165
- (class<<self;self;end).module_eval do
166
- define_method(:on_read, m)
143
+ class Handler < Coolio::Socket
144
+ def initialize(io, on_message)
145
+ super(io)
146
+ if io.is_a?(TCPSocket)
147
+ opt = [1, @timeout.to_i].pack('I!I!') # { int l_onoff; int l_linger; }
148
+ io.setsockopt(Socket::SOL_SOCKET, Socket::SO_LINGER, opt)
149
+ end
150
+ $log.trace { "accepted fluent socket object_id=#{self.object_id}" }
151
+ @on_message = on_message
167
152
  end
168
- m.call(data)
169
- end
170
153
 
171
- def on_read_json(data)
172
- @y << data
173
- rescue
174
- $log.error "forward error: #{$!.to_s}"
175
- $log.error_backtrace
176
- close
177
- end
154
+ def on_connect
155
+ end
178
156
 
179
- def on_read_msgpack(data)
180
- @u.feed_each(data, &@on_message)
181
- rescue
182
- $log.error "forward error: #{$!.to_s}"
183
- $log.error_backtrace
184
- close
185
- end
157
+ def on_read(data)
158
+ first = data[0]
159
+ if first == '{' || first == '['
160
+ m = method(:on_read_json)
161
+ @y = Yajl::Parser.new
162
+ @y.on_parse_complete = @on_message
163
+ else
164
+ m = method(:on_read_msgpack)
165
+ @u = MessagePack::Unpacker.new
166
+ end
167
+
168
+ (class << self; self; end).module_eval do
169
+ define_method(:on_read, m)
170
+ end
171
+ m.call(data)
172
+ end
173
+
174
+ def on_read_json(data)
175
+ @y << data
176
+ rescue
177
+ $log.error "forward error: #{$!.to_s}"
178
+ $log.error_backtrace
179
+ close
180
+ end
181
+
182
+ def on_read_msgpack(data)
183
+ @u.feed_each(data, &@on_message)
184
+ rescue
185
+ $log.error "forward error: #{$!.to_s}"
186
+ $log.error_backtrace
187
+ close
188
+ end
186
189
 
187
- def on_close
188
- $log.trace { "closed fluent socket object_id=#{self.object_id}" }
190
+ def on_close
191
+ $log.trace { "closed fluent socket object_id=#{self.object_id}" }
192
+ end
189
193
  end
190
- end
191
194
 
192
- class HeartbeatRequestHandler < Coolio::IO
193
- def initialize(io, callback)
194
- super(io)
195
- @io = io
196
- @callback = callback
195
+ class HeartbeatRequestHandler < Coolio::IO
196
+ def initialize(io, callback)
197
+ super(io)
198
+ @io = io
199
+ @callback = callback
200
+ end
201
+
202
+ def on_readable
203
+ begin
204
+ msg, addr = @io.recvfrom(1024)
205
+ rescue Errno::EAGAIN, Errno::EWOULDBLOCK, Errno::EINTR
206
+ return
207
+ end
208
+ host = addr[3]
209
+ port = addr[1]
210
+ @callback.call(host, port, msg)
211
+ rescue
212
+ # TODO log?
213
+ end
197
214
  end
198
215
 
199
- def on_readable
216
+ def on_heartbeat_request(host, port, msg)
217
+ #$log.trace "heartbeat request from #{host}:#{port}"
200
218
  begin
201
- msg, addr = @io.recvfrom(1024)
219
+ @usock.send "\0", 0, host, port
202
220
  rescue Errno::EAGAIN, Errno::EWOULDBLOCK, Errno::EINTR
203
- return
204
221
  end
205
- host = addr[3]
206
- port = addr[1]
207
- @callback.call(host, port, msg)
208
- rescue
209
- # TODO log?
210
- end
211
- end
212
-
213
- def on_heartbeat_request(host, port, msg)
214
- #$log.trace "heartbeat request from #{host}:#{port}"
215
- begin
216
- @usock.send "\0", 0, host, port
217
- rescue Errno::EAGAIN, Errno::EWOULDBLOCK, Errno::EINTR
218
222
  end
219
223
  end
220
224
  end
221
-
222
-
223
- end
224
-