Class: LogStash::Inputs::Generator

Inherits:
Threadable 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

Constant Summary

Constants included from Config::Mixin

Config::Mixin::CONFIGSORT

Instance Attribute Summary

Attributes inherited from Base

#params, #threadable

Attributes included from Config::Mixin

#config, #original_params

Attributes inherited from Plugin

#logger, #params

Instance Method Summary collapse

Methods inherited from Threadable

#initialize

Methods inherited from Base

#initialize, #tag

Methods included from Config::Mixin

#config_init, included

Methods inherited from Plugin

#eql?, #finished, #finished?, #hash, #initialize, #inspect, lookup, #reload, #running?, #shutdown, #terminating?, #to_s

Constructor Details

This class inherits a constructor from LogStash::Inputs::Threadable

Instance Method Details

#registerObject



52
53
54
55
56
# 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) ⇒ Object

def register



58
59
60
61
62
63
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 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

#teardownObject



89
90
91
92
93
94
95
96
# File 'lib/logstash/inputs/generator.rb', line 89

def teardown
  @codec.flush do |event|
    decorate(event)
    event["host"] = @host
    queue << event
  end
  finished
end