Class: Gitlab::Metrics::Samplers::ActionCableSampler

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

Constant Summary collapse

DEFAULT_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

#safe_sample, #sleep_interval

Methods inherited from Daemon

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

Constructor Details

#initialize(action_cable: ::ActionCable.server, **options) ⇒ ActionCableSampler

Returns a new instance of ActionCableSampler.



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

def initialize(action_cable: ::ActionCable.server, **options)
  super(**options)
  @action_cable = action_cable
end

Instance Method Details

#metricsObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/gitlab/metrics/samplers/action_cable_sampler.rb', line 14

def metrics
  @metrics ||= {
    active_connections: ::Gitlab::Metrics.gauge(
      :action_cable_active_connections, 'Number of ActionCable WS clients currently connected'
    ),
    pool_min_size: ::Gitlab::Metrics.gauge(
      :action_cable_pool_min_size, 'Minimum number of worker threads in ActionCable thread pool'
    ),
    pool_max_size: ::Gitlab::Metrics.gauge(
      :action_cable_pool_max_size, 'Maximum number of worker threads in ActionCable thread pool'
    ),
    pool_current_size: ::Gitlab::Metrics.gauge(
      :action_cable_pool_current_size, 'Current number of worker threads in ActionCable thread pool'
    ),
    pool_largest_size: ::Gitlab::Metrics.gauge(
      :action_cable_pool_largest_size, 'Largest number of worker threads observed so far in ActionCable thread pool'
    ),
    pool_completed_tasks: ::Gitlab::Metrics.gauge(
      :action_cable_pool_tasks_total, 'Total number of tasks executed in ActionCable thread pool'
    ),
    pool_pending_tasks: ::Gitlab::Metrics.gauge(
      :action_cable_pool_pending_tasks, 'Number of tasks waiting to be executed in ActionCable thread pool'
    )
  }
end

#sampleObject



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/gitlab/metrics/samplers/action_cable_sampler.rb', line 40

def sample
  pool = @action_cable.worker_pool.executor

  metrics[:active_connections].set({}, @action_cable.connections.size)
  metrics[:pool_min_size].set({}, pool.min_length)
  metrics[:pool_max_size].set({}, pool.max_length)
  metrics[:pool_current_size].set({}, pool.length)
  metrics[:pool_largest_size].set({}, pool.largest_length)
  metrics[:pool_completed_tasks].set({}, pool.completed_task_count)
  metrics[:pool_pending_tasks].set({}, pool.queue_length)
end