mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 06:37:19 -04:00
- Add a sleep filter
This commit is contained in:
parent
fea60c8b9d
commit
69538dc33e
2 changed files with 45 additions and 0 deletions
|
@ -21,6 +21,8 @@
|
|||
tagging events on failure. (#328, patch by Neil Prosser)
|
||||
- new: uaparser: parses user agent strings in to structured data based on
|
||||
BrowserScope data (#347, patch by Dan Everton)
|
||||
- new: sleep: sleeps a given amount of time before passing the event.
|
||||
Useful for rate limiting or replay simulation.
|
||||
|
||||
## outputs
|
||||
- fix bug in mongo output that would fail to load bson_java support
|
||||
|
|
43
lib/logstash/filters/sleep.rb
Normal file
43
lib/logstash/filters/sleep.rb
Normal file
|
@ -0,0 +1,43 @@
|
|||
require "logstash/filters/base"
|
||||
require "logstash/namespace"
|
||||
|
||||
# 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.
|
||||
class LogStash::Filters::Sleep < LogStash::Filters::Base
|
||||
config_name "sleep"
|
||||
plugin_status "experimental"
|
||||
|
||||
# The length of time to sleep, in seconds, for every event.
|
||||
#
|
||||
# This can be a number (eg, 0.5), or a string (eg, "%{foo}")
|
||||
# The second form (string with a field value) is useful if
|
||||
# you have an attribute of your event that you want to use
|
||||
# to indicate the amount of time to sleep.
|
||||
#
|
||||
# Example:
|
||||
#
|
||||
# filter {
|
||||
# sleep {
|
||||
# # Sleep 1 second for every event.
|
||||
# duration => "1"
|
||||
# }
|
||||
# }
|
||||
config :duration, :validate => :string, :required => true
|
||||
|
||||
public
|
||||
def register
|
||||
# nothing to do
|
||||
end # def register
|
||||
|
||||
public
|
||||
def filter(event)
|
||||
return unless filter?(event)
|
||||
|
||||
case @duration
|
||||
when Fixnum, Float; sleep(@duration)
|
||||
else; sleep(event.sprintf(@duration).to_f)
|
||||
end
|
||||
filter_matched(event)
|
||||
end # def filter
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue