我正在尝试实现自定义fluentd解析器插件。根据{{3}}的建议,我创建了以下名为parser_unordered_multiline.rb
的文件,并将其放在/etc/td-agent/plugin/
位置。
# @Package: Fluentd
# @Module: Unordered Multiline Parser Plugin
# @Author: Amyth Singh <mail@amythsingh.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
module Fluent
class TextParser
class UnorderedMultilineParser < Parser
Plugin.register_parser('unordered_multiline', self)
## Define configuration params
config_param :delimiter, :string, :default => " "
config_param :time_format, :string, :default => nil
## configures our parser plugin
def configure(conf)
super
if @delimiter.length != 1
raise ConfigError, "delimiter must be a single character. #{@delimiter} is not."
end
@time_parser = TimeParser.new(@time_format)
end
def parse(text)
time, key_values = text.split(" ", 2)
time = @time_parser.parse(time)
record = {}
key_values.split(@delimiter).each { |kv|
k, v = kv.split("=", 2)
record[k] = v
}
yield time, record
end
end
end
end
我使用docs中给出的相同代码(只是使用不同的名称),但流利的日志显示错误:
unexpected error error="uninitialized constant Fluent::TextParser::Parser"
以下是完整堆栈跟踪
2015-12-23 14:38:23 +0530 [info]: starting fluentd-0.10.50
2015-12-23 14:38:23 +0530 [info]: reading config file path="/etc/td-agent/td-agent.conf"
2015-12-23 14:38:23 +0530 [error]: unexpected error error="uninitialized constant Fluent::TextParser::Parser"
2015-12-23 14:38:23 +0530 [error]: /etc/td-agent/plugin/parser_unordered_multiline.rb:21:in `<class:TextParser>'
2015-12-23 14:38:23 +0530 [error]: /etc/td-agent/plugin/parser_unordered_multiline.rb:20:in `<module:Fluent>'
2015-12-23 14:38:23 +0530 [error]: /etc/td-agent/plugin/parser_unordered_multiline.rb:19:in `<top (required)>'
2015-12-23 14:38:23 +0530 [error]: /opt/td-agent/embedded/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
2015-12-23 14:38:23 +0530 [error]: /opt/td-agent/embedded/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
2015-12-23 14:38:23 +0530 [error]: /opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/fluentd-0.10.50/lib/fluent/plugin.rb:59:in `block in load_plugin_dir'
2015-12-23 14:38:23 +0530 [error]: /opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/fluentd-0.10.50/lib/fluent/plugin.rb:57:in `each'
2015-12-23 14:38:23 +0530 [error]: /opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/fluentd-0.10.50/lib/fluent/plugin.rb:57:in `load_plugin_dir'
2015-12-23 14:38:23 +0530 [error]: /opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/fluentd-0.10.50/lib/fluent/engine.rb:129:in `load_plugin_dir'
2015-12-23 14:38:23 +0530 [error]: /opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/fluentd-0.10.50/lib/fluent/supervisor.rb:369:in `block in init_engine'
2015-12-23 14:38:23 +0530 [error]: /opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/fluentd-0.10.50/lib/fluent/supervisor.rb:366:in `each'
2015-12-23 14:38:23 +0530 [error]: /opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/fluentd-0.10.50/lib/fluent/supervisor.rb:366:in `init_engine'
2015-12-23 14:38:23 +0530 [error]: /opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/fluentd-0.10.50/lib/fluent/supervisor.rb:129:in `block in start'
2015-12-23 14:38:23 +0530 [error]: /opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/fluentd-0.10.50/lib/fluent/supervisor.rb:246:in `call'
2015-12-23 14:38:23 +0530 [error]: /opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/fluentd-0.10.50/lib/fluent/supervisor.rb:246:in `main_process'
2015-12-23 14:38:23 +0530 [error]: /opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/fluentd-0.10.50/lib/fluent/supervisor.rb:221:in `block in supervise'
2015-12-23 14:38:23 +0530 [error]: /opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/fluentd-0.10.50/lib/fluent/supervisor.rb:220:in `fork'
2015-12-23 14:38:23 +0530 [error]: /opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/fluentd-0.10.50/lib/fluent/supervisor.rb:220:in `supervise'
2015-12-23 14:38:23 +0530 [error]: /opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/fluentd-0.10.50/lib/fluent/supervisor.rb:126:in `start'
2015-12-23 14:38:23 +0530 [error]: /opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/fluentd-0.10.50/lib/fluent/command/fluentd.rb:160:in `<top (required)>'
2015-12-23 14:38:23 +0530 [error]: /opt/td-agent/embedded/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:73:in `require'
2015-12-23 14:38:23 +0530 [error]: /opt/td-agent/embedded/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:73:in `require'
2015-12-23 14:38:23 +0530 [error]: /opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/fluentd-0.10.50/bin/fluentd:6:in `<top (required)>'
2015-12-23 14:38:23 +0530 [error]: /opt/td-agent/embedded/bin/fluentd:23:in `load'
2015-12-23 14:38:23 +0530 [error]: /opt/td-agent/embedded/bin/fluentd:23:in `<top (required)>'
2015-12-23 14:38:23 +0530 [error]: /usr/sbin/td-agent:7:in `load'
2015-12-23 14:38:23 +0530 [error]: /usr/sbin/td-agent:7:in `<main>'
2015-12-23 14:38:23 +0530 [info]: process finished code=256
2015-12-23 14:38:23 +0530 [warn]: process died within 1 second. exit.
这就是我的配置文件的样子。
<source>
type tail
path /var/log/mail/mail*
pos_file /var/log/td-agent/tmp/access.log
exclude_path ["/var/log/mail/*.gz", "/var/log/mail/*.zip"]
read_from_head true
time_format %M %d %H:%M:%S
port 5140
format unordered_multiline
tag mail
</source>
<match mail>
type copy
<store>
type elasticsearch
logstash_format true
flush_interval 30s
</store>
</match>
我对红宝石很流利,很流利,有人可以告诉我这个错误到底是什么吗?
根据example in the documentation,即使路径似乎也是正确的