Class: Upfluence::Instrumentation::ActiveRecordPoolInstrumenter

Inherits:
PeriodicInstrumenter show all
Defined in:
lib/upfluence/instrumentation/active_record_pool_instrumenter.rb

Constant Summary collapse

KEYS =
i[
  size connections busy dead idle waiting
].freeze

Instance Method Summary collapse

Methods inherited from PeriodicInstrumenter

#initialize, #start, #stop

Constructor Details

This class inherits a constructor from Upfluence::Instrumentation::PeriodicInstrumenter

Instance Method Details

#metricsObject



15
16
17
18
19
# File 'lib/upfluence/instrumentation/active_record_pool_instrumenter.rb', line 15

def metrics
  KEYS.reduce({}) do |acc, k|
    acc.merge(k => { docstring: "Gauge for #{k}" })
  end
end

#prefixObject



11
12
13
# File 'lib/upfluence/instrumentation/active_record_pool_instrumenter.rb', line 11

def prefix
  'active_record_pool'
end

#valuesObject



21
22
23
24
25
26
27
# File 'lib/upfluence/instrumentation/active_record_pool_instrumenter.rb', line 21

def values
  return {} unless ActiveRecord::Base.connected?

  ActiveRecord::Base.connection_pool.stat.slice(*KEYS).reduce({}) do |acc, (k, v)|
    acc.merge(k => [{ value: v }])
  end
end