Sha256: 8a4f3f8c508675f3fa8bc68eed28fb2453b4cf03f9885d5c99163862e609e248
Contents?: true
Size: 1.17 KB
Versions: 4
Compression:
Stored size: 1.17 KB
Contents
# frozen_string_literal: true require 'connection_pool' module Vmpooler class PoolManager class GenericConnectionPool < ConnectionPool # Extend the ConnectionPool class with instrumentation # https://github.com/mperham/connection_pool/blob/master/lib/connection_pool.rb def initialize(options = {}, &block) super(options, &block) @metrics = options[:metrics] @metric_prefix = options[:metric_prefix] @metric_prefix = 'connectionpool' if @metric_prefix.nil? || @metric_prefix == '' end def with_metrics(options = {}) Thread.handle_interrupt(Exception => :never) do start = Time.now conn = checkout(options) timespan_ms = ((Time.now - start) * 1000).to_i @metrics&.gauge(@metric_prefix + '.available', @available.length) @metrics&.timing(@metric_prefix + '.waited', timespan_ms) begin Thread.handle_interrupt(Exception => :immediate) do yield conn end ensure checkin @metrics&.gauge(@metric_prefix + '.available', @available.length) end end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems