Class: LogStash::Inputs::Generator

Inherits:
Threadable
  • Object
show all
Defined in:
lib/logstash/inputs/generator.rb

Overview

Generate random log events.

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

An event is generated first

Instance Method Summary collapse

Instance Method Details

#registerObject



55
56
57
58
59
60
61
# File 'lib/logstash/inputs/generator.rb', line 55

def register
  @host = Socket.gethostname.freeze
  @count = Array(@count).first

  @host_name_field = ecs_select[disabled: 'host', v1: '[host][name]']
  @sequence_field = ecs_select[disabled: 'sequence', v1: '[event][sequence]']
end

#run(queue) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/logstash/inputs/generator.rb', line 64

def run(queue)
  @queue = queue

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

  number = 0
  while !stop? && (@count <= 0 || number < @count)
    @lines.each do |line|
      @codec.decode(line.clone) do |event|
        decorate_and_set_fields(event, number)
        queue << event
      end
    end
    number += 1
  end # loop

  do_flush_codec(queue)
end

#LogStash::Inputs::BaseObject



89
90
91
# File 'lib/logstash/inputs/generator.rb', line 89

def stop
  do_flush_codec(@queue)
end