Sha256: 5fd9818f4fcef5813b3c71fada12438eced1727c3bf743523deab8dc8fd8647e

Contents?: true

Size: 1.8 KB

Versions: 46

Compression:

Stored size: 1.8 KB

Contents

module Appsignal
  module Probes
    class PumaProbe
      def initialize
        @hostname = Appsignal.config[:hostname] || Socket.gethostname
      end

      # @api private
      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

      private

      attr_reader :hostname

      def gauge(field, count, tags = {})
        Appsignal.set_gauge("puma_#{field}", count, tags.merge(:hostname => hostname))
      end

      def count_if_present(counts, key, stats)
        stat_value = stats[key]
        return unless stat_value
        counts[key] ||= 0
        counts[key] += stat_value
      end

      def fetch_puma_stats
        ::Puma.stats
      rescue NoMethodError # rubocop:disable Lint/HandleExceptions
      end
    end
  end
end

Version data entries

46 entries across 46 versions & 1 rubygems

Version Path
appsignal-2.11.10-java lib/appsignal/probes/puma.rb
appsignal-2.11.10 lib/appsignal/probes/puma.rb
appsignal-3.0.6-java lib/appsignal/probes/puma.rb
appsignal-3.0.6 lib/appsignal/probes/puma.rb
appsignal-3.0.5-java lib/appsignal/probes/puma.rb
appsignal-3.0.5 lib/appsignal/probes/puma.rb
appsignal-3.0.4-java lib/appsignal/probes/puma.rb
appsignal-3.0.4 lib/appsignal/probes/puma.rb
appsignal-3.0.4.alpha.1-java lib/appsignal/probes/puma.rb
appsignal-3.0.4.alpha.1 lib/appsignal/probes/puma.rb
appsignal-3.0.3-java lib/appsignal/probes/puma.rb
appsignal-3.0.3 lib/appsignal/probes/puma.rb
appsignal-3.0.2-java lib/appsignal/probes/puma.rb
appsignal-3.0.2 lib/appsignal/probes/puma.rb
appsignal-3.0.1-java lib/appsignal/probes/puma.rb
appsignal-3.0.1 lib/appsignal/probes/puma.rb
appsignal-3.0.0-java lib/appsignal/probes/puma.rb
appsignal-3.0.0 lib/appsignal/probes/puma.rb
appsignal-3.0.0.rc.1 lib/appsignal/probes/puma.rb
appsignal-3.0.0.rc.1-java lib/appsignal/probes/puma.rb