Class: Fluent::MysqlRecordOutput
- Inherits:
-
BufferedOutput
- Object
- BufferedOutput
- Fluent::MysqlRecordOutput
- Includes:
- SetTagKeyMixin, SetTimeKeyMixin
- Defined in:
- lib/fluent/plugin/out_mysqlrecord.rb
Instance Attribute Summary collapse
-
#handler ⇒ Object
Returns the value of attribute handler.
Instance Method Summary collapse
- #client ⇒ Object
- #configure(conf) ⇒ Object
- #format(tag, time, record) ⇒ Object
-
#initialize ⇒ MysqlRecordOutput
constructor
A new instance of MysqlRecordOutput.
- #shutdown ⇒ Object
- #start ⇒ Object
- #write(chunk) ⇒ Object
Constructor Details
#initialize ⇒ MysqlRecordOutput
Returns a new instance of MysqlRecordOutput.
19 20 21 22 |
# File 'lib/fluent/plugin/out_mysqlrecord.rb', line 19 def initialize super require 'mysql2-cs-bind' end |
Instance Attribute Details
#handler ⇒ Object
Returns the value of attribute handler.
17 18 19 |
# File 'lib/fluent/plugin/out_mysqlrecord.rb', line 17 def handler @handler end |
Instance Method Details
#client ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/fluent/plugin/out_mysqlrecord.rb', line 40 def client Mysql2::Client.new({ :host => @host, :port => @port, :username => @username, :password => @password, :database => @database, :flags => Mysql2::Client::MULTI_STATEMENTS, }) end |
#configure(conf) ⇒ Object
24 25 26 |
# File 'lib/fluent/plugin/out_mysqlrecord.rb', line 24 def configure(conf) super end |
#format(tag, time, record) ⇒ Object
36 37 38 |
# File 'lib/fluent/plugin/out_mysqlrecord.rb', line 36 def format(tag, time, record) [tag, time, record].to_msgpack end |
#shutdown ⇒ Object
32 33 34 |
# File 'lib/fluent/plugin/out_mysqlrecord.rb', line 32 def shutdown super end |
#start ⇒ Object
28 29 30 |
# File 'lib/fluent/plugin/out_mysqlrecord.rb', line 28 def start super end |
#write(chunk) ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/fluent/plugin/out_mysqlrecord.rb', line 48 def write(chunk) handler = self.client chunk.msgpack_each { |tag, time, data| cols = data.keys.join(",") placeholders = data.map{|k| '?'}.join(',') sql = "INSERT INTO #{@table} (#{cols}) VALUES (#{placeholders})" handler.xquery(sql, data.values) } handler.close end |