diff options
author | Pavel <pavel.evst@gmail.com> | 2016-11-09 01:10:16 +0800 |
---|---|---|
committer | Pavel <pavel.evst@gmail.com> | 2016-11-09 01:10:16 +0800 |
commit | 35b6898f7cb5223e1de4edc1b4539e05dfd83d41 (patch) | |
tree | 7c6e3c551b13e3f3ab8aa0a4aeb9c3a8d2557bfd /activerecord/lib | |
parent | e91dd52d561e61ec4e41bf01c20d9e1aab579e4a (diff) | |
download | rails-35b6898f7cb5223e1de4edc1b4539e05dfd83d41.tar.gz rails-35b6898f7cb5223e1de4edc1b4539e05dfd83d41.tar.bz2 rails-35b6898f7cb5223e1de4edc1b4539e05dfd83d41.zip |
Add ActiveRecord::Base.connection_pool.stat
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb index e9ecb78e27..9727d63883 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb @@ -581,6 +581,24 @@ module ActiveRecord @available.num_waiting end + # Return connection pool's usage statistic + # Example: + # + # ActiveRecord::Base.connection_pool.stat # => { size: 15, connections: 1, busy: 1, dead: 0, idle: 0, waiting: 0, checkout_timeout: 5 } + 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 + private #-- # this is unfortunately not concurrent |