Class: Fluent::ThresholdOutput

Inherits:
Output
  • Object
show all
Includes:
HandleTagNameMixin
Defined in:
lib/fluent/plugin/out_threshold.rb

Instance Method Summary collapse

Constructor Details

#initializeThresholdOutput

<match *>

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

</match>



21
22
23
# File 'lib/fluent/plugin/out_threshold.rb', line 21

def initialize
  super
end

Instance Method Details

#configure(conf) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# 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) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
113
# 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) ⇒ Object

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



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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# 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

#shutdownObject



52
53
54
# File 'lib/fluent/plugin/out_threshold.rb', line 52

def shutdown
  super
end

#startObject



48
49
50
# File 'lib/fluent/plugin/out_threshold.rb', line 48

def start
  super
end