class Fluent::MysqlExplainFilter
Public Class Methods
new()
click to toggle source
Calls superclass method
# File lib/fluent/plugin/filter_mysql_explain.rb, line 5 def initialize super require "mysql2" end
Public Instance Methods
client()
click to toggle source
# File lib/fluent/plugin/filter_mysql_explain.rb, line 70 def client Mysql2::Client.new({ :host => @host, :port => @port, :username => @username, :password => @password, :database => @database, :flags => Mysql2::Client::MULTI_STATEMENTS, }) end
configure(conf)
click to toggle source
Calls superclass method
# File lib/fluent/plugin/filter_mysql_explain.rb, line 19 def configure(conf) super end
explain(sql)
click to toggle source
# File lib/fluent/plugin/filter_mysql_explain.rb, line 39 def explain(sql) if sql.empty? || !explainable?(sql) return '' end res = StringIO.new handler = self.client handler.query("EXPLAIN #{sql}").each_with_index do |row, i| res.puts "*************************** #{i+1}. row ***************************" row.each do |key, value| value ||= "NULL" res.puts key.rjust(13, ' ') + ": #{value}" end end handler.close res.rewind res.read end
explainable?(sql)
click to toggle source
# File lib/fluent/plugin/filter_mysql_explain.rb, line 60 def explainable?(sql) sql =~/^\s*(SELECT|DELETE|INSERT|REPLACE|UPDATE)/i end
filter(tag, time, record)
click to toggle source
# File lib/fluent/plugin/filter_mysql_explain.rb, line 31 def filter(tag, time, record) sql = hash_get(record, @sql_key) if !sql.nil? && !sql.empty? record[@added_key] = explain(sql) end record end
hash_get(hash, key)
click to toggle source
# File lib/fluent/plugin/filter_mysql_explain.rb, line 64 def hash_get(hash, key) return hash[key.to_sym] if hash.key?(key.to_sym) return hash[key] if hash.key?(key) nil end
shutdown()
click to toggle source
Calls superclass method
# File lib/fluent/plugin/filter_mysql_explain.rb, line 27 def shutdown super end
start()
click to toggle source
Calls superclass method
# File lib/fluent/plugin/filter_mysql_explain.rb, line 23 def start super end