2017-10-14 173 views

回答

1

您可以修補同在Rails4

方法star這是你可以在Rails4加也。

ActiveRecord::Base.connection_pool.synchronize do 
    { connections: ActiveRecord::Base.connection_pool.connections.size } 
end 

=> {:連接=> 1}

Rails5 stat定義

# File activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb, line 583 
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 
+0

我不得不猴補丁都MysqlAdapter和連接池。但它的工作。事實上,我可以通過擴展,獲得保持連接的線程列表。這一切都有幫助。 – CppNoob