Class: Fluent::ClickHouseJsonOutput

Inherits:
BufferedOutput
  • Object
show all
Includes:
SetTagKeyMixin, SetTimeKeyMixin
Defined in:
lib/fluent/plugin/out_clickhousejson.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeClickHouseJsonOutput

Returns a new instance of ClickHouseJsonOutput.



21
22
23
24
25
# File 'lib/fluent/plugin/out_clickhousejson.rb', line 21

def initialize
  super

  require 'click_house'
end

Instance Attribute Details

#handlerObject

Returns the value of attribute handler.



18
19
20
# File 'lib/fluent/plugin/out_clickhousejson.rb', line 18

def handler
  @handler
end

#pathObject

Returns the value of attribute path.



19
20
21
# File 'lib/fluent/plugin/out_clickhousejson.rb', line 19

def path
  @path
end

Instance Method Details

#configure(conf) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/fluent/plugin/out_clickhousejson.rb', line 31

def configure(conf)
  super
  @cf = {}
  if conf['username']
    @cf['username'] = conf['username']
  end
  if conf['password']
    @cf['password'] = conf['password']
  end

  if conf['url']
    @url = @url.split(',').map { |m| m.strip }
  elsif conf['host']
    @cf['host'] = conf['host']
  end
  if conf['port']
    @cf['port'] = conf['port']
  end

  @cf['database'] = conf['database']
end

#format(tag, time, record) ⇒ Object



61
62
63
# File 'lib/fluent/plugin/out_clickhousejson.rb', line 61

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

#shutdownObject



57
58
59
# File 'lib/fluent/plugin/out_clickhousejson.rb', line 57

def shutdown
  super
end

#startObject



53
54
55
# File 'lib/fluent/plugin/out_clickhousejson.rb', line 53

def start
  super
end

#write(chunk) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/fluent/plugin/out_clickhousejson.rb', line 65

def write(chunk)
  ClickHouse.config do |config|
    config.host = @cf['host']
    config.port = @cf['port']
    config.username = @cf['username']
    config.password = @cf['password']
  end
  ClickHouse.connection.insert(@table) do |rows|
    chunk.msgpack_each { |tag, time, record|
      rows << JSON.parse(JSON[record])
    }
    rows
  end
end