Module: Fluent::Plugin

Defined in:
lib/fluent/plugin.rb,
lib/fluent/plugin/base.rb,
lib/fluent/plugin/input.rb,
lib/fluent/plugin/buffer.rb,
lib/fluent/plugin/filter.rb,
lib/fluent/plugin/in_tcp.rb,
lib/fluent/plugin/in_udp.rb,
lib/fluent/plugin/output.rb,
lib/fluent/plugin/parser.rb,
lib/fluent/plugin/sd_srv.rb,
lib/fluent/plugin/in_exec.rb,
lib/fluent/plugin/in_http.rb,
lib/fluent/plugin/in_tail.rb,
lib/fluent/plugin/in_unix.rb,
lib/fluent/plugin/metrics.rb,
lib/fluent/plugin/sd_file.rb,
lib/fluent/plugin/storage.rb,
lib/fluent/plugin/buf_file.rb,
lib/fluent/plugin/out_copy.rb,
lib/fluent/plugin/out_exec.rb,
lib/fluent/plugin/out_file.rb,
lib/fluent/plugin/out_null.rb,
lib/fluent/plugin/formatter.rb,
lib/fluent/plugin/in_sample.rb,
lib/fluent/plugin/in_syslog.rb,
lib/fluent/plugin/sd_static.rb,
lib/fluent/plugin/buf_memory.rb,
lib/fluent/plugin/in_forward.rb,
lib/fluent/plugin/in_gc_stat.rb,
lib/fluent/plugin/out_stdout.rb,
lib/fluent/plugin/parser_csv.rb,
lib/fluent/plugin/parser_tsv.rb,
lib/fluent/plugin/bare_output.rb,
lib/fluent/plugin/filter_grep.rb,
lib/fluent/plugin/out_forward.rb,
lib/fluent/plugin/out_relabel.rb,
lib/fluent/plugin/parser_json.rb,
lib/fluent/plugin/parser_ltsv.rb,
lib/fluent/plugin/parser_none.rb,
lib/fluent/plugin/buffer/chunk.rb,
lib/fluent/plugin/compressable.rb,
lib/fluent/plugin/multi_output.rb,
lib/fluent/plugin/parser_nginx.rb,
lib/fluent/plugin/filter_parser.rb,
lib/fluent/plugin/filter_stdout.rb,
lib/fluent/plugin/formatter_csv.rb,
lib/fluent/plugin/formatter_tsv.rb,
lib/fluent/plugin/metrics_local.rb,
lib/fluent/plugin/parser_apache.rb,
lib/fluent/plugin/parser_regexp.rb,
lib/fluent/plugin/parser_syslog.rb,
lib/fluent/plugin/storage_local.rb,
lib/fluent/plugin/formatter_hash.rb,
lib/fluent/plugin/formatter_json.rb,
lib/fluent/plugin/formatter_ltsv.rb,
lib/fluent/plugin/in_debug_agent.rb,
lib/fluent/plugin/out_roundrobin.rb,
lib/fluent/plugin/owned_by_mixin.rb,
lib/fluent/plugin/parser_apache2.rb,
lib/fluent/plugin/parser_msgpack.rb,
lib/fluent/plugin/buf_file_single.rb,
lib/fluent/plugin/in_object_space.rb,
lib/fluent/plugin/out_exec_filter.rb,
lib/fluent/plugin/formatter_stdout.rb,
lib/fluent/plugin/in_monitor_agent.rb,
lib/fluent/plugin/parser_multiline.rb,
lib/fluent/plugin/buffer/file_chunk.rb,
lib/fluent/plugin/formatter_msgpack.rb,
lib/fluent/plugin/out_forward/error.rb,
lib/fluent/plugin/service_discovery.rb,
lib/fluent/plugin/formatter_out_file.rb,
lib/fluent/plugin/out_secondary_file.rb,
lib/fluent/plugin/buffer/memory_chunk.rb,
lib/fluent/plugin/in_tail/group_watch.rb,
lib/fluent/plugin/parser_apache_error.rb,
lib/fluent/plugin/in_tail/position_file.rb,
lib/fluent/plugin/formatter_single_value.rb,
lib/fluent/plugin/out_forward/ack_handler.rb,
lib/fluent/plugin/buffer/file_single_chunk.rb,
lib/fluent/plugin/out_forward/socket_cache.rb,
lib/fluent/plugin/filter_record_transformer.rb,
lib/fluent/plugin/out_forward/load_balancer.rb,
lib/fluent/plugin/out_forward/failure_detector.rb,
lib/fluent/plugin/out_forward/connection_manager.rb,
lib/fluent/plugin/out_forward/handshake_protocol.rb,
lib/fluent/plugin/out_http.rb

Defined Under Namespace

Modules: Compressable, FeatureAvailabilityChecker, Newline, OwnedByMixin Classes: Apache2Parser, ApacheErrorParser, ApacheParser, BareOutput, Base, Buffer, CSVParser, CopyOutput, CsvFormatter, DebugAgentInput, ExecFilterOutput, ExecInput, ExecOutput, FileBuffer, FileOutput, FileServiceDiscovery, FileSingleBuffer, Filter, Formatter, ForwardInput, ForwardOutput, GCStatInput, GrepFilter, HTTPOutput, HashFormatter, HttpInput, InHttpParser, Input, JSONFormatter, JSONParser, LabeledTSVFormatter, LabeledTSVParser, LocalMetrics, LocalStorage, MemoryBuffer, MessagePackFormatter, MessagePackParser, Metrics, MonitorAgentInput, MultiOutput, MultilineParser, NginxParser, NoneParser, NullOutput, ObjectSpaceInput, OutFileFormatter, Output, Parser, ParserFilter, ProcWrappedFormatter, RecordTransformerFilter, RegexpParser, RelabelOutput, RoundRobinOutput, SampleInput, SecondaryFileOutput, ServiceDiscovery, SingleValueFormatter, SrvServiceDiscovery, StaticServiceDiscovery, StdoutFilter, StdoutFormatter, StdoutOutput, Storage, SyslogInput, SyslogParser, TSVFormatter, TSVParser, TailInput, TcpInput, UdpInput, UnixInput

Constant Summary collapse

SEARCH_PATHS =
[]
INPUT_REGISTRY =

first class plugins (instantiated by Engine)

Registry.new(:input,     'fluent/plugin/in_',         dir_search_prefix: 'in_')
OUTPUT_REGISTRY =
Registry.new(:output,    'fluent/plugin/out_',        dir_search_prefix: 'out_')
FILTER_REGISTRY =
Registry.new(:filter,    'fluent/plugin/filter_',     dir_search_prefix: 'filter_')
BUFFER_REGISTRY =

feature plugin: second class plugins (instantiated by Plugins or Helpers)

Registry.new(:buffer,    'fluent/plugin/buf_',        dir_search_prefix: 'buf_')
PARSER_REGISTRY =
Registry.new(:parser,    'fluent/plugin/parser_',     dir_search_prefix: 'parser_')
FORMATTER_REGISTRY =
Registry.new(:formatter, 'fluent/plugin/formatter_',  dir_search_prefix: 'formatter_')
STORAGE_REGISTRY =
Registry.new(:storage,   'fluent/plugin/storage_',    dir_search_prefix: 'storage_')
SD_REGISTRY =
Registry.new(:sd,        'fluent/plugin/sd_',         dir_search_prefix: 'sd_')
METRICS_REGISTRY =
Registry.new(:metrics,   'fluent/plugin/metrics_',    dir_search_prefix: 'metrics_')
REGISTRIES =
[INPUT_REGISTRY, OUTPUT_REGISTRY, FILTER_REGISTRY, BUFFER_REGISTRY, PARSER_REGISTRY, FORMATTER_REGISTRY, STORAGE_REGISTRY, SD_REGISTRY, METRICS_REGISTRY]

Class Method Summary collapse

Class Method Details

.add_plugin_dir(dir) ⇒ Object



102
103
104
105
106
107
# File 'lib/fluent/plugin.rb', line 102

def self.add_plugin_dir(dir)
  REGISTRIES.each do |r|
    r.paths.push(dir)
  end
  nil
end

.lookup_type_from_class(klass_or_its_name) ⇒ Object



91
92
93
94
95
96
97
98
99
100
# File 'lib/fluent/plugin.rb', line 91

def self.lookup_type_from_class(klass_or_its_name)
  klass = if klass_or_its_name.is_a? Class
            klass_or_its_name
          elsif klass_or_its_name.is_a? String
            eval(klass_or_its_name) # const_get can't handle qualified klass name (ex: A::B)
          else
            raise ArgumentError, "invalid argument type #{klass_or_its_name.class}: #{klass_or_its_name}"
          end
  REGISTRIES.reduce(nil){|a, r| a || r.reverse_lookup(klass) }
end

.new_buffer(type, parent: nil) ⇒ Object



121
122
123
# File 'lib/fluent/plugin.rb', line 121

def self.new_buffer(type, parent: nil)
  new_impl('buffer', BUFFER_REGISTRY, type, parent)
end

.new_filter(type) ⇒ Object



117
118
119
# File 'lib/fluent/plugin.rb', line 117

def self.new_filter(type)
  new_impl('filter', FILTER_REGISTRY, type)
end

.new_formatter(type, parent: nil) ⇒ Object



150
151
152
# File 'lib/fluent/plugin.rb', line 150

def self.new_formatter(type, parent: nil)
  new_impl('formatter', FORMATTER_REGISTRY, type, parent)
end

.new_impl(kind, registry, type, parent = nil) ⇒ Object



167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/fluent/plugin.rb', line 167

def self.new_impl(kind, registry, type, parent=nil)
  # "'type' not found" is handled by registry
  obj = registry.lookup(type)
  impl = case
         when obj.is_a?(Class)
           obj.new
         when obj.respond_to?(:call) && obj.arity == 0
           obj.call
         else
           raise Fluent::ConfigError, "#{kind} plugin '#{type}' is not a Class nor callable (without arguments)."
         end
  if parent && impl.respond_to?("owner=")
    impl.owner = parent
  end
  impl.extend FeatureAvailabilityChecker
  impl
end

.new_input(type) ⇒ Object



109
110
111
# File 'lib/fluent/plugin.rb', line 109

def self.new_input(type)
  new_impl('input', INPUT_REGISTRY, type)
end

.new_metrics(type, parent: nil) ⇒ Object



129
130
131
# File 'lib/fluent/plugin.rb', line 129

def self.new_metrics(type, parent: nil)
  new_impl('metrics', METRICS_REGISTRY, type, parent)
end

.new_output(type) ⇒ Object



113
114
115
# File 'lib/fluent/plugin.rb', line 113

def self.new_output(type)
  new_impl('output', OUTPUT_REGISTRY, type)
end

.new_parser(type, parent: nil) ⇒ Object



138
139
140
141
142
143
144
145
146
147
148
# File 'lib/fluent/plugin.rb', line 138

def self.new_parser(type, parent: nil)
  if type[0] == '/' && type[-1] == '/'
    # This usage is not recommended for new API... create RegexpParser directly
    require 'fluent/parser'
    impl = Fluent::TextParser.lookup(type)
    impl.extend FeatureAvailabilityChecker
    impl
  else
    new_impl('parser', PARSER_REGISTRY, type, parent)
  end
end

.new_sd(type, parent: nil) ⇒ Object Also known as: new_service_discovery



125
126
127
# File 'lib/fluent/plugin.rb', line 125

def self.new_sd(type, parent: nil)
  new_impl('sd', SD_REGISTRY, type, parent)
end

.new_storage(type, parent: nil) ⇒ Object



154
155
156
# File 'lib/fluent/plugin.rb', line 154

def self.new_storage(type, parent: nil)
  new_impl('storage', STORAGE_REGISTRY, type, parent)
end

.register_buffer(type, klass) ⇒ Object



55
56
57
# File 'lib/fluent/plugin.rb', line 55

def self.register_buffer(type, klass)
  register_impl('buffer', BUFFER_REGISTRY, type, klass)
end

.register_filter(type, klass) ⇒ Object



51
52
53
# File 'lib/fluent/plugin.rb', line 51

def self.register_filter(type, klass)
  register_impl('filter', FILTER_REGISTRY, type, klass)
end

.register_formatter(type, klass_or_proc) ⇒ Object



77
78
79
80
81
82
83
84
85
# File 'lib/fluent/plugin.rb', line 77

def self.register_formatter(type, klass_or_proc)
  if klass_or_proc.respond_to?(:call) && klass_or_proc.arity == 3 # Proc.new { |tag, time, record| }
    # This usage is not recommended for new API
    require 'fluent/formatter'
    register_impl('formatter', FORMATTER_REGISTRY, type, Proc.new { Fluent::TextFormatter::ProcWrappedFormatter.new(klass_or_proc) })
  else
    register_impl('formatter', FORMATTER_REGISTRY, type, klass_or_proc)
  end
end

.register_impl(kind, registry, type, value) ⇒ Object



158
159
160
161
162
163
164
165
# File 'lib/fluent/plugin.rb', line 158

def self.register_impl(kind, registry, type, value)
  if !value.is_a?(Class) && !value.respond_to?(:call)
    raise Fluent::ConfigError, "Invalid implementation as #{kind} plugin: '#{type}'. It must be a Class, or callable."
  end
  registry.register(type, value)
  $log.trace "registered #{kind} plugin '#{type}'" if defined?($log)
  nil
end

.register_input(type, klass) ⇒ Object



43
44
45
# File 'lib/fluent/plugin.rb', line 43

def self.register_input(type, klass)
  register_impl('input', INPUT_REGISTRY, type, klass)
end

.register_metrics(type, klass) ⇒ Object



63
64
65
# File 'lib/fluent/plugin.rb', line 63

def self.register_metrics(type, klass)
  register_impl('metrics', METRICS_REGISTRY, type, klass)
end

.register_output(type, klass) ⇒ Object



47
48
49
# File 'lib/fluent/plugin.rb', line 47

def self.register_output(type, klass)
  register_impl('output', OUTPUT_REGISTRY, type, klass)
end

.register_parser(type, klass_or_proc) ⇒ Object



67
68
69
70
71
72
73
74
75
# File 'lib/fluent/plugin.rb', line 67

def self.register_parser(type, klass_or_proc)
  if klass_or_proc.is_a?(Regexp)
    # This usage is not recommended for new API
    require 'fluent/parser'
    register_impl('parser', PARSER_REGISTRY, type, Proc.new { Fluent::TextParser::RegexpParser.new(klass_or_proc) })
  else
    register_impl('parser', PARSER_REGISTRY, type, klass_or_proc)
  end
end

.register_sd(type, klass) ⇒ Object



59
60
61
# File 'lib/fluent/plugin.rb', line 59

def self.register_sd(type, klass)
  register_impl('sd', SD_REGISTRY, type, klass)
end

.register_storage(type, klass) ⇒ Object



87
88
89
# File 'lib/fluent/plugin.rb', line 87

def self.register_storage(type, klass)
  register_impl('storage', STORAGE_REGISTRY, type, klass)
end