Class: Fluent::MackerelHostidTagOutput
- Inherits:
-
Output
- Object
- Output
- Fluent::MackerelHostidTagOutput
- Defined in:
- lib/fluent/plugin/out_mackerel_hostid_tag.rb
Instance Method Summary collapse
- #configure(conf) ⇒ Object
- #emit(tag, es, chain) ⇒ Object
-
#initialize ⇒ MackerelHostidTagOutput
constructor
A new instance of MackerelHostidTagOutput.
Constructor Details
#initialize ⇒ MackerelHostidTagOutput
Returns a new instance of MackerelHostidTagOutput.
22 23 24 |
# File 'lib/fluent/plugin/out_mackerel_hostid_tag.rb', line 22 def initialize super end |
Instance Method Details
#configure(conf) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/fluent/plugin/out_mackerel_hostid_tag.rb', line 26 def configure(conf) super @hostid = File.open(@hostid_path).read if @add_to == 'record' and @key_name.nil? raise Fluent::ConfigError, "'key_name' must be specified" end if @remove_prefix @removed_prefix_string = @remove_prefix + '.' @removed_length = @removed_prefix_string.length end @added_prefix_string = @add_prefix + '.' unless @add_prefix.nil? end |
#emit(tag, es, chain) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/fluent/plugin/out_mackerel_hostid_tag.rb', line 39 def emit(tag, es, chain) if @remove_prefix and ( (tag.start_with?(@removed_prefix_string) and tag.length > @removed_length) or tag == @remove_prefix) tag = tag[@removed_length..-1] end if tag.length > 0 tag = @added_prefix_string + tag if @added_prefix_string else tag = @add_prefix end if @add_to == 'tag' tag = [tag, @hostid].join('.') end es.each do |time, record| if @add_to == 'record' record[@key_name] = @hostid end router.emit(tag, time, record) end chain.next end |