summaryrefslogtreecommitdiff
path: root/lib/gitlab/metrics/samplers
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-09-19 01:45:44 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-09-19 01:45:44 +0000
commit85dc423f7090da0a52c73eb66faf22ddb20efff9 (patch)
tree9160f299afd8c80c038f08e1545be119f5e3f1e1 /lib/gitlab/metrics/samplers
parent15c2c8c66dbe422588e5411eee7e68f1fa440bb8 (diff)
downloadgitlab-ce-85dc423f7090da0a52c73eb66faf22ddb20efff9.tar.gz
Add latest changes from gitlab-org/gitlab@13-4-stable-ee
Diffstat (limited to 'lib/gitlab/metrics/samplers')
-rw-r--r--lib/gitlab/metrics/samplers/action_cable_sampler.rb63
-rw-r--r--lib/gitlab/metrics/samplers/base_sampler.rb2
-rw-r--r--lib/gitlab/metrics/samplers/puma_sampler.rb2
3 files changed, 65 insertions, 2 deletions
diff --git a/lib/gitlab/metrics/samplers/action_cable_sampler.rb b/lib/gitlab/metrics/samplers/action_cable_sampler.rb
new file mode 100644
index 00000000000..9f4979fa673
--- /dev/null
+++ b/lib/gitlab/metrics/samplers/action_cable_sampler.rb
@@ -0,0 +1,63 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Metrics
+ module Samplers
+ class ActionCableSampler < BaseSampler
+ SAMPLING_INTERVAL_SECONDS = 5
+
+ def initialize(interval = SAMPLING_INTERVAL_SECONDS, action_cable: ::ActionCable.server)
+ super(interval)
+ @action_cable = action_cable
+ end
+
+ 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
+
+ def sample
+ pool = @action_cable.worker_pool.executor
+ labels = {
+ server_mode: server_mode
+ }
+
+ metrics[:active_connections].set(labels, @action_cable.connections.size)
+ metrics[:pool_min_size].set(labels, pool.min_length)
+ metrics[:pool_max_size].set(labels, pool.max_length)
+ metrics[:pool_current_size].set(labels, pool.length)
+ metrics[:pool_largest_size].set(labels, pool.largest_length)
+ metrics[:pool_completed_tasks].set(labels, pool.completed_task_count)
+ metrics[:pool_pending_tasks].set(labels, pool.queue_length)
+ end
+
+ private
+
+ def server_mode
+ Gitlab::ActionCable::Config.in_app? ? 'in-app' : 'standalone'
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/metrics/samplers/base_sampler.rb b/lib/gitlab/metrics/samplers/base_sampler.rb
index ff3e7be567f..39a49187e45 100644
--- a/lib/gitlab/metrics/samplers/base_sampler.rb
+++ b/lib/gitlab/metrics/samplers/base_sampler.rb
@@ -21,7 +21,7 @@ module Gitlab
def safe_sample
sample
rescue => e
- Rails.logger.warn("#{self.class}: #{e}, stopping") # rubocop:disable Gitlab/RailsLogger
+ Gitlab::AppLogger.warn("#{self.class}: #{e}, stopping")
stop
end
diff --git a/lib/gitlab/metrics/samplers/puma_sampler.rb b/lib/gitlab/metrics/samplers/puma_sampler.rb
index b5343d5e66a..d295beb59f1 100644
--- a/lib/gitlab/metrics/samplers/puma_sampler.rb
+++ b/lib/gitlab/metrics/samplers/puma_sampler.rb
@@ -42,7 +42,7 @@ module Gitlab
def puma_stats
Puma.stats
rescue NoMethodError
- Rails.logger.info "PumaSampler: stats are not available yet, waiting for Puma to boot" # rubocop:disable Gitlab/RailsLogger
+ Gitlab::AppLogger.info "PumaSampler: stats are not available yet, waiting for Puma to boot"
nil
end