Class: Fluent::PingPortInput

Inherits:
Input
  • Object
show all
Defined in:
lib/fluent/plugin/in_ping_port.rb

Instance Method Summary collapse

Constructor Details

#initializePingPortInput



5
6
7
8
9
# File 'lib/fluent/plugin/in_ping_port.rb', line 5

def initialize
  super
  require 'socket'
  require 'timeout'
end

Instance Method Details

#configure(conf) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/fluent/plugin/in_ping_port.rb', line 22

def configure(conf)
  super
  @ports = @port.split(',')
  @state = @ports.inject({}) {|state, port|
    state[port] = 0
    state
  }
end

#emit_ping_portObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/fluent/plugin/in_ping_port.rb', line 46

def emit_ping_port
  begin
    @ports.each do |port|
      unless is_port_open?(@host, port, @timeout)
        @state[port] = @state[port] + 1
        if @state[port] >= @retry_count
          record = {
            'message' => "#{@host}:#{port} Connect Error."
          }
          router.emit @tag, Fluent::Engine.now, record
          @state[port] = 0
        end
      else
        @state[port] = 0
      end
    end
  rescue => e
    log.error e
  end
end

#runObject



39
40
41
42
43
44
# File 'lib/fluent/plugin/in_ping_port.rb', line 39

def run
  loop do
    Thread.new(&method(:emit_ping_port))
    sleep @interval
  end
end

#shutdownObject



35
36
37
# File 'lib/fluent/plugin/in_ping_port.rb', line 35

def shutdown
  Thread.kill(@thread)
end

#startObject



31
32
33
# File 'lib/fluent/plugin/in_ping_port.rb', line 31

def start
  @thread = Thread.new(&method(:run))
end