Class: Fluent::UDPInput

Inherits:
Input
  • Object
show all
Includes:
DetachMultiProcessMixin
Defined in:
lib/fluent/plugin/in_udp.rb

Instance Method Summary collapse

Constructor Details

#initializeUDPInput

Returns a new instance of UDPInput.



7
8
9
# File 'lib/fluent/plugin/in_udp.rb', line 7

def initialize
  super
end

Instance Method Details

#configure(conf) ⇒ Object



15
16
17
# File 'lib/fluent/plugin/in_udp.rb', line 15

def configure(conf)
  super
end

#runObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/fluent/plugin/in_udp.rb', line 37

def run
   loop do
     text, sender =  @udp_s.recvfrom(1024)
     begin
     j_obj = JSON.parse(text)
     rescue
      $log.debug "Parse error : #{text} \n #{$!.to_s}" 
     j_obj = {}
     end
     time = j_obj['t']
     time = time.to_i
     if time == 0
       time = Engine.now
     end
     
     tag = j_obj['tag'] || "unknown"
     
     Engine.emit(tag, time, j_obj)
   end
rescue
  $log.error "unexpected error", :error=>$!.to_s
  $log.error_backtrace
end

#shutdownObject



32
33
34
35
# File 'lib/fluent/plugin/in_udp.rb', line 32

def shutdown
  @udp_s.close
  @thread.join
end

#startObject



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/fluent/plugin/in_udp.rb', line 19

def start
 
  @udp_s = UDPSocket.new
   
 
  detach_multi_process do
    super
       @udp_s.bind(@bind, @port)
       $log.debug "listening UDP on #{@bind}:#{@port}"
    @thread = Thread.new(&method(:run))
  end
end