Class: Fluent::ClickHouseOutput

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeClickHouseOutput

Returns a new instance of ClickHouseOutput.



23
24
25
26
27
# File 'lib/fluent/plugin/out_clickhouse.rb', line 23

def initialize
  super

  require 'clickhouse'
end

Instance Attribute Details

#handlerObject

Returns the value of attribute handler.



20
21
22
# File 'lib/fluent/plugin/out_clickhouse.rb', line 20

def handler
  @handler
end

#pathObject

Returns the value of attribute path.



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

def path
  @path
end

Instance Method Details

#configure(conf) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/fluent/plugin/out_clickhouse.rb', line 33

def configure(conf)
  super
  if conf['columns']
    @columns = conf['columns'].split(',').map { |m| m.strip }
  end
  @config = {}
  if conf['username']
    @config['username'] = conf['username']
  end
  if conf['password']
    @config['password'] = conf['password']
  end

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

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

#format(tag, time, record) ⇒ Object



66
67
68
# File 'lib/fluent/plugin/out_clickhouse.rb', line 66

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

#shutdownObject



62
63
64
# File 'lib/fluent/plugin/out_clickhouse.rb', line 62

def shutdown
  super
end

#startObject



58
59
60
# File 'lib/fluent/plugin/out_clickhouse.rb', line 58

def start
  super
end

#write(chunk) ⇒ Object



70
71
72
73
74
75
76
77
78
# File 'lib/fluent/plugin/out_clickhouse.rb', line 70

def write(chunk)
  Clickhouse.establish_connection(@config)
  Clickhouse.connection.insert_rows(@table, :names => @columns) { |rows|
    chunk.msgpack_each { |tag, time, record|
      rows << @columns.map { |m| record[m] }
    }
    rows
  }
end