Class: Fluent::Plugin::TimescaleDB

Inherits:
Output
  • Object
show all
Defined in:
lib/fluent/plugin/out_timescaledb.rb

Instance Method Summary collapse

Instance Method Details

#closeObject



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

def close
  @conn.close if @conn
end

#format(tag, time, record) ⇒ Object



29
30
31
# File 'lib/fluent/plugin/out_timescaledb.rb', line 29

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

#formatted_to_msgpack_binaryObject



33
34
35
# File 'lib/fluent/plugin/out_timescaledb.rb', line 33

def formatted_to_msgpack_binary
  true
end

#startObject



12
13
14
15
16
17
# File 'lib/fluent/plugin/out_timescaledb.rb', line 12

def start
  super

  @conn = PG.connect(@db_conn_string)
  @conn.prepare('insert_record', "INSERT INTO \"#{@db_table_name}\" (time, tag, record) VALUES ($1, $2, $3::jsonb)")
end

#write(chunk) ⇒ Object



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

def write(chunk)
  chunk.msgpack_each do | tag, time, record |
    @conn.exec_prepared('insert_record', [Time.at(time.to_f), tag, record.to_json])
  end
end