Class: Gitlab::Metrics::Samplers::PumaSampler

Inherits:
BaseSampler show all
Defined in:
lib/gitlab/metrics/samplers/puma_sampler.rb

Constant Summary collapse

SAMPLING_INTERVAL_SECONDS =
5

Instance Attribute Summary

Attributes inherited from BaseSampler

#interval

Attributes inherited from Daemon

#thread

Instance Method Summary collapse

Methods inherited from BaseSampler

#initialize, #safe_sample, #sleep_interval

Methods inherited from Daemon

#enabled?, #initialize, initialize_instance, instance, #start, #stop, #thread?, #thread_name

Constructor Details

This class inherits a constructor from Gitlab::Metrics::Samplers::BaseSampler

Instance Method Details

#init_metricsObject


13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/gitlab/metrics/samplers/puma_sampler.rb', line 13

def init_metrics
  {
    puma_workers:            ::Gitlab::Metrics.gauge(:puma_workers, 'Total number of workers'),
    puma_running_workers:    ::Gitlab::Metrics.gauge(:puma_running_workers, 'Number of active workers'),
    puma_stale_workers:      ::Gitlab::Metrics.gauge(:puma_stale_workers, 'Number of stale workers'),
    puma_running:            ::Gitlab::Metrics.gauge(:puma_running, 'Number of running threads'),
    puma_queued_connections: ::Gitlab::Metrics.gauge(:puma_queued_connections, 'Number of connections in that worker\'s "todo" set waiting for a worker thread'),
    puma_active_connections: ::Gitlab::Metrics.gauge(:puma_active_connections, 'Number of threads processing a request'),
    puma_pool_capacity:      ::Gitlab::Metrics.gauge(:puma_pool_capacity, 'Number of requests the worker is capable of taking right now'),
    puma_max_threads:        ::Gitlab::Metrics.gauge(:puma_max_threads, 'Maximum number of worker threads'),
    puma_idle_threads:       ::Gitlab::Metrics.gauge(:puma_idle_threads, 'Number of spawned threads which are not processing a request')
  }
end

#metricsObject


9
10
11
# File 'lib/gitlab/metrics/samplers/puma_sampler.rb', line 9

def metrics
  @metrics ||= init_metrics
end

#sampleObject


27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/gitlab/metrics/samplers/puma_sampler.rb', line 27

def sample
  json_stats = puma_stats
  return unless json_stats

  stats = Gitlab::Json.parse(json_stats)

  if cluster?(stats)
    sample_cluster(stats)
  else
    sample_single_worker(stats)
  end
end