Skip to content

Instantly share code, notes, and snippets.

@kazuhisa
Last active December 11, 2015 23:48
Show Gist options
  • Select an option

  • Save kazuhisa/4678727 to your computer and use it in GitHub Desktop.

Select an option

Save kazuhisa/4678727 to your computer and use it in GitHub Desktop.
Railsでarproxy + fluent-loggerを使ってSQLのログを記録してみた
# add
gem "arproxy"
gem "fluent-logger"
# config/initializers/query_tracer.rb
class QueryTracer < Arproxy::Base
def execute(sql, name=nil)
result = nil
ms = Benchmark.ms{ result = super(sql, name) }
Fluent::Logger::FluentLogger.open(nil, :host=>'192.168.1.1', :port=>24224)
Fluent::Logger.post("rails.sql", {name: name, time: ms.to_f, sql: sql})
result
end
end
Arproxy.configure do |config|
config.adapter = ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
config.use QueryTracer
end
Arproxy.enable!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment