class Fluent::HerokuPostgresOutput

Attributes

database[RW]
handler[RW]
host[RW]
password[RW]
port[RW]
username[RW]

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_heroku_postgres.rb, line 20
def initialize
  super
  require 'pg'
end

Public Instance Methods

client() click to toggle source
# File lib/fluent/plugin/out_heroku_postgres.rb, line 58
def client
  PG::Connection.new({
    :host => @host, :port => @port,
    :user => @username, :password => @password,
    :dbname => @database
  })
end
configure(conf) click to toggle source

We don’t currently support mysql’s analogous json format

Calls superclass method
# File lib/fluent/plugin/out_heroku_postgres.rb, line 26
def configure(conf)
  super

  parse_heroku_postgres_url!

  if @format == 'json'
    @format_proc = Proc.new{|tag, time, record| record.to_json}
  else
    @key_names = @key_names.split(',')
    @format_proc = Proc.new{|tag, time, record| @key_names.map{|k| record[k]}}
  end

  if @columns.nil? and @sql.nil?
    raise Fluent::ConfigError, "columns or sql MUST be specified, but missing"
  end
  if @columns and @sql
    raise Fluent::ConfigError, "both of columns and sql are specified, but specify one of them"
  end
end
format(tag, time, record) click to toggle source
# File lib/fluent/plugin/out_heroku_postgres.rb, line 54
def format(tag, time, record)
  [tag, time, @format_proc.call(tag, time, record)].to_msgpack
end
shutdown() click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_heroku_postgres.rb, line 50
def shutdown
  super
end
start() click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_heroku_postgres.rb, line 46
def start
  super
end
write(chunk) click to toggle source
# File lib/fluent/plugin/out_heroku_postgres.rb, line 66
def write(chunk)
  handler = self.client
  handler.prepare("write", @sql)
  chunk.msgpack_each { |tag, time, data|
    handler.exec_prepared("write", data)
  }
  handler.close
end

Private Instance Methods

parse_heroku_postgres_url!() click to toggle source
# File lib/fluent/plugin/out_heroku_postgres.rb, line 77
def parse_heroku_postgres_url!
  parsed_url = URI.parse(@heroku_postgres_url)
  @host = parsed_url.host
  @port = parsed_url.port
  @database = parsed_url.path.sub(/\//, '')
  @username = parsed_url.user
  @password = parsed_url.password
end