class Fluent::Plugin::Rds_LogInput

Public Class Methods

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

Public Instance Methods

configure(conf) click to toggle source
Calls superclass method
# File lib/fluent/plugin/in_rds_log.rb, line 24
def configure(conf)
  super
  if @log_type.nil?
    log.error "fluent-plugin-rds-log: missing parameter log_type is {slow_log|general_log}"
  end
end
shutdown() click to toggle source
Calls superclass method
# File lib/fluent/plugin/in_rds_log.rb, line 36
def shutdown
  super
end
start() click to toggle source
Calls superclass method
# File lib/fluent/plugin/in_rds_log.rb, line 31
def start
  super
  timer_execute(:in_rds_log_timer, @refresh_interval, &method(:watch))
end

Private Instance Methods

connect(host) click to toggle source
# File lib/fluent/plugin/in_rds_log.rb, line 42
def connect(host)
  begin
    client = Mysql2::Client.new({
      :host => host,
      :port => @port,
      :username => @username,
      :password => @password,
      :reconnect => @auto_reconnect,
      :database => 'mysql'
    })
    return client
  rescue
    log.error "fluent-plugin-rds-log: cannot connect RDS [#{host}]"
  end
  return nil
end
output(host) click to toggle source
# File lib/fluent/plugin/in_rds_log.rb, line 65
def output(host)
  client = connect(host)
  return if client.nil?
  output_log_data = query(client)
  return if output_log_data.nil?
  output_log_data.each do |row|
    row.delete_if{|key,value| value == ''}
    row['host'] = host if @add_host
    router.emit(tag, Fluent::Engine.now, row)
  end
  client.close
end
query(client) click to toggle source
# File lib/fluent/plugin/in_rds_log.rb, line 78
def query(client)
  begin
    client.query("CALL mysql.rds_rotate_#{@log_type}")
    sql = "SELECT * FROM mysql.#{@log_type}_backup"
    unless @where.nil?
      sql += " WHERE #{@where}"
    end
    output_log_data = client.query(sql, :cast => false)
  rescue Exception => e
    log.error "fluent-plugin-rds-log: ERROR Occurred!"
    log.error "#{e.message}\n#{e.backtrace.join("\n")}"
    return nil
  end
end
watch() click to toggle source
# File lib/fluent/plugin/in_rds_log.rb, line 59
def watch
  @host.split(',').each do |host|
    output(host)
  end
end