Module: Puma::Plugin::Telemetry::CommonData

Included in:
ClusteredData, WorkerData
Defined in:
lib/puma/plugin/telemetry/data.rb

Overview

Helper for working with Puma stats

Constant Summary collapse

TELEMETRY_TO_METHODS =
{
  'workers.booted' => :workers_booted,
  'workers.total' => :workers_total,
  'workers.spawned_threads' => :workers_spawned_threads,
  'workers.max_threads' => :workers_max_threads,
  'workers.requests_count' => :workers_requests_count,
  'queue.backlog' => :queue_backlog,
  'queue.capacity' => :queue_capacity
}.freeze

Instance Method Summary collapse

Instance Method Details

#initialize(stats) ⇒ Object



18
19
20
# File 'lib/puma/plugin/telemetry/data.rb', line 18

def initialize(stats)
  @stats = stats
end

#metrics(selected) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/puma/plugin/telemetry/data.rb', line 30

def metrics(selected)
  selected.each_with_object({}) do |metric, obj|
    next unless TELEMETRY_TO_METHODS.key?(metric)

    obj[metric] = public_send(TELEMETRY_TO_METHODS[metric])
  end
end

#workers_bootedObject



22
23
24
# File 'lib/puma/plugin/telemetry/data.rb', line 22

def workers_booted
  @stats.fetch(:booted_workers, 1)
end

#workers_totalObject



26
27
28
# File 'lib/puma/plugin/telemetry/data.rb', line 26

def workers_total
  @stats.fetch(:workers, 1)
end