Parent

Class/Module Index [+]

Quicksearch

Fluent::HttpInput

Public Class Methods

new() click to toggle source
# File lib/fluent/plugin/in_http.rb, line 28
def initialize
  require 'webrick/httputils'
  super
end

Public Instance Methods

configure(conf) click to toggle source
# File lib/fluent/plugin/in_http.rb, line 38
def configure(conf)
  super
end
on_request(path_info, params) click to toggle source
# File lib/fluent/plugin/in_http.rb, line 105
def on_request(path_info, params)
  begin
    path = path_info[1..-1]  # remove /
    tag = path.split('/').join('.')

    if msgpack = params['msgpack']
      record = MessagePack.unpack(msgpack)

    elsif js = params['json']
      record = JSON.parse(js)

    else
      raise "'json' or 'msgpack' parameter is required"
    end

    time = params['time']
    time = time.to_i
    if time == 0
      time = Engine.now
    end

  rescue
    return ["400 Bad Request", {'Content-type'=>'text/plain'}, "400 Bad Request\n#{$!}\n"]
  end

  # TODO server error
  begin
    Engine.emit(tag, time, record)
  rescue
    return ["500 Internal Server Error", {'Content-type'=>'text/plain'}, "500 Internal Server Error\n#{$!}\n"]
  end

  return ["200 OK", {'Content-type'=>'text/plain'}, ""]
end
run() click to toggle source
# File lib/fluent/plugin/in_http.rb, line 98
def run
  @loop.run
rescue
  $log.error "unexpected error", :error=>$!.to_s
  $log.error_backtrace
end
shutdown() click to toggle source
# File lib/fluent/plugin/in_http.rb, line 91
def shutdown
  @loop.watchers.each {|w| w.detach }
  @loop.stop
  @lsock.close
  @thread.join
end
start() click to toggle source
# File lib/fluent/plugin/in_http.rb, line 73
def start
  $log.debug "listening http on #{@bind}:#{@port}"
  lsock = TCPServer.new(@bind, @port)

  detach_multi_process do
    super
    @km = KeepaliveManager.new(@keepalive_timeout)
    #@lsock = Coolio::TCPServer.new(@bind, @port, Handler, @km, method(:on_request), @body_size_limit)
    @lsock = Coolio::TCPServer.new(lsock, nil, Handler, @km, method(:on_request), @body_size_limit)

    @loop = Coolio::Loop.new
    @loop.attach(@km)
    @loop.attach(@lsock)

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

[Validate]

Generated with the Darkfish Rdoc Generator 2.