Class: Fluent::ConsulOutput

Inherits:
BufferedOutput
  • Object
show all
Defined in:
lib/fluent/plugin/out_consul.rb

Instance Method Summary collapse

Constructor Details

#initializeConsulOutput

Returns a new instance of ConsulOutput.



9
10
11
12
# File 'lib/fluent/plugin/out_consul.rb', line 9

def initialize
  super
  require 'diplomat'
end

Instance Method Details

#configure(conf) ⇒ Object



14
15
16
17
18
19
# File 'lib/fluent/plugin/out_consul.rb', line 14

def configure(conf)
  super
  ::Diplomat.configure do |config|
    config.url = @consul_uri
  end
end

#consul_kvs_fmt(data) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/fluent/plugin/out_consul.rb', line 33

def consul_kvs_fmt(data)
  kvs = []

  if data.is_a?(Array) || data.is_a?(Hash)
    data.each_key do |k|
      r_kvs = consul_kvs_fmt(data[k])
      r_kvs.each do |r_kv|
        kvs << { key: '/' + k + r_kv[:key], value: r_kv[:value] }
      end
    end
  else
    kvs << { key: '', value: data }
  end

  kvs
end

#format(tag, time, record) ⇒ Object



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

def format(tag, time, record)
  [tag, time, record].to_msgpack
end

#write(chunk) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/fluent/plugin/out_consul.rb', line 25

def write(chunk)
  chunk.msgpack_each do |tag, time, record|
    consul_kvs_fmt(record).each do |kv|
      ::Diplomat.put(@kv_prefix + '/' + tag + kv[:key].to_s, kv[:value].to_s)
    end
  end
end