class LogStash::Inputs::Generator

Generate random log events.

The general intention of this is to test performance of plugins.

An event is generated first

Public Instance Methods

register() click to toggle source
# File lib/logstash/inputs/generator.rb, line 52
def register
  @host = Socket.gethostname
  @count = @count.first if @count.is_a?(Array)
  @lines = [@message] if @lines.nil?
end
run(queue) click to toggle source
# File lib/logstash/inputs/generator.rb, line 58
def run(queue)
  number = 0

  if @message == "stdin"
    @logger.info("Generator plugin reading a line from stdin")
    @message = $stdin.readline
    @logger.debug("Generator line read complete", :message => @message)
  end

  while !finished? && (@count <= 0 || number < @count)
    @lines.each do |line|
      @codec.decode(line.clone) do |event|
        decorate(event)
        event["host"] = @host
        event["sequence"] = number
        queue << event
      end
    end
    number += 1
  end # loop

  if @codec.respond_to?(:flush)
    @codec.flush do |event|
      decorate(event)
      event["host"] = @host
      queue << event
    end
  end
end
teardown() click to toggle source
# File lib/logstash/inputs/generator.rb, line 89
def teardown
  @codec.flush do |event|
    decorate(event)
    event["host"] = @host
    queue << event
  end
  finished
end