Class: Upfluence::Instrumentation::PumaInstrumenter

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

Constant Summary collapse

KEYS =
%i[backlog_thread running_thread busy_thread pool_capacity requests_count].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from PeriodicInstrumenter

#initialize, #start, #stop

Constructor Details

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

Instance Attribute Details

#server=(value) ⇒ Object (writeonly)

Sets the attribute server

Parameters:

  • value

    the value to set the attribute server to.



9
10
11
# File 'lib/upfluence/instrumentation/puma_instrumenter.rb', line 9

def server=(value)
  @server = value
end

Instance Method Details

#metricsObject



15
16
17
18
19
# File 'lib/upfluence/instrumentation/puma_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/puma_instrumenter.rb', line 11

def prefix
  'puma'
end

#valuesObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/upfluence/instrumentation/puma_instrumenter.rb', line 21

def values
  return {} unless @server

  stats = @server.stats

  {
    requests_count: stats[:requests_count],
    backlog_thread: stats[:backlog],
    running_thread: stats[:running],
    busy_thread:    stats[:busy_threads],
    pool_capacity:  stats[:max_threads]
  }.compact.transform_values { |value| [{ value: value }] }
rescue NoMethodError
  {}
end