class Fluent::ThresholdOutput

Public Class Methods

new() click to toggle source

<match *>

condition eq | ne | gl | ge | lt | le | string | regexp
threshold <float> | <integer> | <string> | <regexp>
target_key <key_name>

</match>

Calls superclass method
# File lib/fluent/plugin/out_threshold.rb, line 21
def initialize
  super
end

Public Instance Methods

configure(conf) click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_threshold.rb, line 25
def configure(conf)
  super

  @labelled = !conf['@label'].nil?

  if !@labelled && !@remove_tag_prefix && !@remove_tag_suffix && !@add_tag_prefix && !@add_tag_suffix
    raise ConfigError, "fluent-plugin-threshold: Set 'remove_tag_prefix', 'remove_tag_suffix', 'add_tag_prefix' or 'add_tag_suffix'."
  end

  # You can also refer raw parameter via conf[name].
  unless @operator
    raise ConfigError, "fluent-plugin-threshold: 'operator' parameter is required"
  end

  unless @threshold
    raise ConfigError, "fluent-plugin-threshold: 'threshold' parameter is required"
  end

  unless @target_key
    raise ConfigError, "fluent-plugin-threshold: 'target_key' parameter is required"
  end
end
emit(tag, es, chain) click to toggle source
# File lib/fluent/plugin/out_threshold.rb, line 102
def emit(tag, es, chain)
  es.each do |time, record|
    _tag = tag.clone
    record = filter_record(_tag, time, record)

    if record.any?
      router.emit(_tag, time, record)
    end
  end

  chain.next
end
filter_record(tag, time, record) click to toggle source

This method is called when an event reaches to Fluentd. Convert the event to a raw string.

Calls superclass method
# File lib/fluent/plugin/out_threshold.rb, line 58
def filter_record(tag, time, record)
  super

  filter_record = {}
  case @operator
  when "eq"
    if record.member?(@target_key) && record[@target_key].to_f == threshold.to_f
      filter_record = record
    end
  when "ne"
    if record.member?(@target_key) && record[@target_key].to_f != threshold.to_f
      filter_record = record
    end
  when "ge"
    if record.member?(@target_key) && record[@target_key].to_f >= threshold.to_f
      filter_record = record
    end
  when "gt"
    if record.member?(@target_key) && record[@target_key].to_f >  threshold.to_f
      filter_record = record
    end
  when "le"
    if record.member?(@target_key) && record[@target_key].to_f <= threshold.to_f
      filter_record = record
    end
  when "lt"
    if record.member?(@target_key) && record[@target_key].to_f <  threshold.to_f
      filter_record = record
    end
  when "string"
    if record.member?(@target_key) && record[@target_key].eql?(threshold)
      filter_record = record
    end
  when "regexp"
    if record.member?(@target_key) && /#{threshold}/ =~ record[@target_key]
      filter_record = record
    end
  else
    raise ArgumentError.new("no such operator: #{@operator}")
  end

  filter_record
end
shutdown() click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_threshold.rb, line 52
def shutdown
  super
end
start() click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_threshold.rb, line 48
def start
  super
end