Class: Vmpooler::PoolManager::GenericConnectionPool
- Inherits:
-
ConnectionPool
- Object
- ConnectionPool
- Vmpooler::PoolManager::GenericConnectionPool
- Defined in:
- lib/vmpooler/generic_connection_pool.rb
Instance Method Summary collapse
-
#health_status ⇒ Hash
Get connection pool health status.
-
#initialize(options = {}, &block) ⇒ GenericConnectionPool
constructor
Extend the ConnectionPool class with instrumentation github.com/mperham/connection_pool/blob/master/lib/connection_pool.rb.
- #with_metrics(options = {}) ⇒ Object
Constructor Details
#initialize(options = {}, &block) ⇒ GenericConnectionPool
Extend the ConnectionPool class with instrumentation github.com/mperham/connection_pool/blob/master/lib/connection_pool.rb
11 12 13 14 15 16 17 18 |
# File 'lib/vmpooler/generic_connection_pool.rb', line 11 def initialize( = {}, &block) super(, &block) @metrics = [:metrics] @connpool_type = [:connpool_type] @connpool_type = 'connectionpool' if @connpool_type.nil? || @connpool_type == '' @connpool_provider = [:connpool_provider] @connpool_provider = 'unknown' if @connpool_provider.nil? || @connpool_provider == '' end |
Instance Method Details
#health_status ⇒ Hash
Get connection pool health status
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/vmpooler/generic_connection_pool.rb', line 40 def health_status { size: @size, available: @available.length, in_use: @size - @available.length, utilization: ((@size - @available.length).to_f / @size * 100).round(2), waiting_threads: (@queue.respond_to?(:length) ? @queue.length : 0), state: determine_health_state } end |
#with_metrics(options = {}) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/vmpooler/generic_connection_pool.rb', line 20 def with_metrics( = {}) Thread.handle_interrupt(Exception => :never) do start = Time.now conn = checkout() timespan_ms = ((Time.now - start) * 1000).to_i @metrics&.gauge("connection_available.#{@connpool_type}.#{@connpool_provider}", @available.length) @metrics&.timing("connection_waited.#{@connpool_type}.#{@connpool_provider}", timespan_ms) begin Thread.handle_interrupt(Exception => :immediate) do yield conn end ensure checkin @metrics&.gauge("connection_available.#{@connpool_type}.#{@connpool_provider}", @available.length) end end end |