Sha256: 5ef06ba28a8c092de2b167d4871ff2e76ec7dd0f1782f26989251eed42902522

Contents?: true

Size: 1.76 KB

Versions: 2

Compression:

Stored size: 1.76 KB

Contents

# encoding: utf-8
require 'logstash/inputs/base'
require 'logstash/namespace'
require 'stud/interval'
require 'socket' # for Socket.gethostname
require '../../../lib/mongo/mongo'

# Generate a repeating message.
#
# This plugin is intented only as an example.

class LogStash::Inputs::Mongoprofile < LogStash::Inputs::Base
  config_name 'mongoprofile'


  # Set how frequently messages should be sent.
  #
  # The default, `1`, means send a message every second.
  config :interval, :validate => :number, :default => 1
  config :url, :validate => :string, :required => true
  config :path, :validate => :string, :required => true
  config :client_host, :validate => :string, :default => '127.0.0.1'

  public
  def register
    @host = Socket.gethostname
    @controller = Controller.new(@host, @url, 'system.profile', 1000, @path, @client_host)
  end # def register

  def run(queue)
    # we can abort the loop if stop? becomes true
    until stop?
      #event = LogStash::Event.new("message" => @message, "host" => @host)

      @controller.get_next_events.each do |event|
        @logger.info("Send event #{event}")

        decorate(event)
        queue << event
      end
      # because the sleep interval can be big, when shutdown happens
      # we want to be able to abort the sleep
      # Stud.stoppable_sleep will frequently evaluate the given block
      # and abort the sleep(@interval) if the return value is true
      Stud.stoppable_sleep(@interval) {stop?}
    end # loop
  end # def run

  def stop
    # nothing to do in this case so it is not necessary to define stop
    # examples of common "stop" tasks:
    #  * close sockets (unblocking blocking reads/accepts)
    #  * cleanup temporary files
    #  * terminate spawned threads
  end
end # class LogStash::Inputs::Mongoprofile

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
logstash-input-mongoprofile-0.0.3 lib/logstash/inputs/mongoprofile.rb
logstash-input-mongoprofile-0.0.2 lib/logstash/inputs/mongoprofile.rb