Class: LogStash::Filters::Sleep
- Defined in:
- lib/logstash/filters/sleep.rb
Overview
Sleep a given amount of time. This will cause logstash to stall for the given amount of time. This is useful for rate limiting, etc.
Constant Summary
Constants inherited from Base
Constants included from Config::Mixin
Instance Attribute Summary
Attributes included from Config::Mixin
Attributes inherited from Plugin
Instance Method Summary collapse
Methods inherited from Base
#execute, #initialize, #threadsafe?
Methods included from Config::Mixin
Methods inherited from Plugin
#eql?, #finished, #finished?, #hash, #initialize, #inspect, lookup, #reload, #running?, #shutdown, #teardown, #terminating?, #to_s
Constructor Details
This class inherits a constructor from LogStash::Filters::Base
Instance Method Details
#filter(event) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/logstash/filters/sleep.rb', line 81 def filter(event) return unless filter?(event) @count += 1 case @time when Fixnum, Float; time = @time when nil; # nothing else; time = event.sprintf(@time).to_f end if @replay clock = event["@timestamp"].to_f if @last_clock delay = clock - @last_clock time = delay/time if time > 0 @logger.debug? && @logger.debug("Sleeping", :delay => time) sleep(time) end end @last_clock = clock else if @count >= @every @count = 0 @logger.debug? && @logger.debug("Sleeping", :delay => time) sleep(time) end end filter_matched(event) end |
#register ⇒ Object
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/logstash/filters/sleep.rb', line 69 def register if @replay && @time.nil? # Default time multiplier is 1 when replay is set. @time = 1 end if @time.nil? raise ArgumentError, "Missing required parameter 'time' for input/eventlog" end @count = 0 end |