Class: Appsignal::Hooks::PumaProbe Private

Inherits:
Object
  • Object
show all
Defined in:
lib/appsignal/hooks/puma.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Constructor Details

#initializePumaProbe

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of PumaProbe.



44
45
46
# File 'lib/appsignal/hooks/puma.rb', line 44

def initialize
  @hostname = Appsignal.config[:hostname] || Socket.gethostname
end

Instance Method Details

#callObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/appsignal/hooks/puma.rb', line 48

def call
  puma_stats = fetch_puma_stats
  return unless puma_stats

  stats = JSON.parse puma_stats, :symbolize_names => true
  counts = {}
  count_keys = [:backlog, :running, :pool_capacity, :max_threads]

  if stats[:worker_status] # Multiple workers
    stats[:worker_status].each do |worker|
      stat = worker[:last_status]
      count_keys.each do |key|
        count_if_present counts, key, stat
      end
    end

    gauge(:workers, stats[:workers], :type => :count)
    gauge(:workers, stats[:booted_workers], :type => :booted)
    gauge(:workers, stats[:old_workers], :type => :old)
  else # Single worker
    count_keys.each do |key|
      count_if_present counts, key, stats
    end
  end

  gauge(:connection_backlog, counts[:backlog]) if counts[:backlog]
  gauge(:pool_capacity, counts[:pool_capacity]) if counts[:pool_capacity]
  gauge(:threads, counts[:running], :type => :running) if counts[:running]
  gauge(:threads, counts[:max_threads], :type => :max) if counts[:max_threads]
end