class LogStash::Inputs::Varnishlog

Read from varnish cache's shared memory log

Public Instance Methods

register() click to toggle source
# File lib/logstash/inputs/varnishlog.rb, line 12
def register
  require 'varnish'
  @vd = Varnish::VSM.VSM_New
  Varnish::VSL.VSL_Setup(@vd)
  Varnish::VSL.VSL_Open(@vd, 1)

end
run(queue) click to toggle source
# File lib/logstash/inputs/varnishlog.rb, line 20
def run(queue)
  @q = queue
  @hostname = Socket.gethostname
  Varnish::VSL.VSL_Dispatch(@vd, self.method(:cb).to_proc, FFI::MemoryPointer.new(:pointer))
end
teardown() click to toggle source
# File lib/logstash/inputs/varnishlog.rb, line 45
def teardown
  finished
end

Private Instance Methods

cb(priv, tag, fd, len, spec, ptr, bitmap) click to toggle source
# File lib/logstash/inputs/varnishlog.rb, line 27
def cb(priv, tag, fd, len, spec, ptr, bitmap)
  begin
    str = ptr.read_string(len)
    event = LogStash::Event.new("message" => str, "host" => @host)
    decorate(event)
    event["varnish_tag"] = tag
    event["varnish_fd"] = fd
    event["varnish_spec"] = spec
    event["varnish_bitmap"] = bitmap
    @q << event
  rescue => e
    @logger.warn("varnishlog exception: #{e.inspect}")
  ensure
    return 0
  end
end