Class: Fluent::Plugin::TcpInput

Inherits:
Input show all
Defined in:
lib/fluent/plugin/in_tcp.rb

Constant Summary

Constants included from Configurable

Configurable::CONFIG_TYPE_REGISTRY

Instance Attribute Summary

Attributes included from Fluent::PluginLoggerMixin

#log

Attributes inherited from Base

#under_plugin_development

Instance Method Summary collapse

Methods included from Fluent::PluginHelper::Mixin

included

Methods included from Fluent::PluginLoggerMixin

included, #initialize, #terminate

Methods included from Fluent::PluginId

#initialize, #plugin_id, #plugin_id_configured?, #plugin_id_for_test?, #plugin_root_dir

Methods inherited from Base

#after_shutdown, #after_shutdown?, #after_start, #after_started?, #before_shutdown, #before_shutdown?, #close, #closed?, #configured?, #context_router, #context_router=, #fluentd_worker_id, #has_router?, #initialize, #inspect, #plugin_root_dir, #shutdown, #shutdown?, #started?, #stop, #stopped?, #string_safe_encoding, #terminate, #terminated?

Methods included from SystemConfig::Mixin

#system_config, #system_config_override

Methods included from Configurable

#config, #configure_proxy_generate, #configured_section_create, included, #initialize, lookup_type, register_type

Instance Method Details

#configure(conf) ⇒ Object



42
43
44
45
46
47
48
49
# File 'lib/fluent/plugin/in_tcp.rb', line 42

def configure(conf)
  compat_parameters_convert(conf, :parser)
  super
  @_event_loop_blocking_timeout = @blocking_timeout
  @source_hostname_key ||= @source_host_key if @source_host_key

  @parser = parser_create
end

#multi_workers_ready?Boolean

Returns:

  • (Boolean)


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

def multi_workers_ready?
  true
end

#startObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/fluent/plugin/in_tcp.rb', line 55

def start
  super

  @buffer = ''
  server_create(:in_tcp_server, @port, bind: @bind) do |data, conn|
    @buffer << data
    begin
      pos = 0
      while i = @buffer.index(@delimiter, pos)
        msg = @buffer[pos...i]
        pos = i + @delimiter.length

        @parser.parse(msg) do |time, record|
          unless time && record
            log.warn "pattern not match", message: msg
            next
          end

          tag = extract_tag_from_record(record)
          tag ||= @tag
          time ||= extract_time_from_record(record) || Fluent::EventTime.now
          record[@source_hostname_key] = conn.remote_host if @source_hostname_key
          router.emit(tag, time, record)
        end
      end
      @buffer.slice!(0, pos) if pos > 0
    end
  end
end