Skip to content

Instantly share code, notes, and snippets.

@Paxa
Created April 20, 2017 12:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Paxa/7627a85863667b207dd8527c41abcee9 to your computer and use it in GitHub Desktop.
Save Paxa/7627a85863667b207dd8527c41abcee9 to your computer and use it in GitHub Desktop.
ActiveRecord pool stats for Rails < 5.1
unless ActiveRecord::ConnectionAdapters::ConnectionPool.method_defined?(:stat) # will be in Rails 5.1
class ActiveRecord::ConnectionAdapters::ConnectionPool
def stat
synchronize do
{
size: size,
connections: @connections.size,
busy: @connections.count { |c| c.in_use? && c.owner.alive? },
dead: @connections.count { |c| c.in_use? && !c.owner.alive? },
idle: @connections.count { |c| !c.in_use? },
waiting: num_waiting_in_queue,
checkout_timeout: checkout_timeout
}
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment