Module: Tpt::Rails::PumaStatsCollector

Defined in:
lib/tpt/rails/puma_stats_collector.rb

Overview

:nodoc:

Defined Under Namespace

Classes: PumaStats

Class Method Summary collapse

Class Method Details

.run(metrics_client:, start_delay: 10, collect_interval: 30) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/tpt/rails/puma_stats_collector.rb', line 57

def run(metrics_client:, start_delay: 10, collect_interval: 30)
  Thread.new do
    # Give Puma time to start
    sleep start_delay

    # Get pod name if set
    pod_name = ENV["KUBE_POD"]

    loop do
      begin
        stats = PumaStats.new(Puma.stats)

        tags = []
        # Add pod_name tag if set
        tags << "pod_name:#{pod_name}" if pod_name

        metrics_client.gauge("puma.workers", stats.workers, tags: tags)
        metrics_client.gauge("puma.booted_workers", stats.booted_workers, tags: tags)
        metrics_client.gauge("puma.running", stats.running, tags: tags)
        metrics_client.gauge("puma.backlog", stats.backlog, tags: tags)
        metrics_client.gauge("puma.pool_capacity", stats.pool_capacity, tags: tags)
        metrics_client.gauge("puma.max_threads", stats.max_threads, tags: tags)
      end

      sleep collect_interval
    end
  end
end