Class: Gitlab::Metrics::Samplers::ThreadsSampler
- Inherits:
-
BaseSampler
- Object
- Daemon
- BaseSampler
- Gitlab::Metrics::Samplers::ThreadsSampler
- Defined in:
- lib/gitlab/metrics/samplers/threads_sampler.rb
Constant Summary collapse
- DEFAULT_SAMPLING_INTERVAL_SECONDS =
5
- KNOWN_PUMA_THREAD_NAMES =
['puma worker check pipe', 'puma server', 'puma threadpool reaper', 'puma threadpool trimmer', 'puma worker check pipe', 'puma stat payload'].freeze
- SIDEKIQ_WORKER_THREAD_NAME =
'sidekiq_worker_thread'
- METRIC_PREFIX =
"gitlab_ruby_threads_"
- METRIC_DESCRIPTIONS =
{ max_expected_threads: "Maximum number of threads expected to be running and performing application work", running_threads: "Number of running Ruby threads by name" }.freeze
Instance Attribute Summary
Attributes inherited from BaseSampler
Attributes inherited from Daemon
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
#metrics ⇒ Object
21 22 23 24 25 |
# File 'lib/gitlab/metrics/samplers/threads_sampler.rb', line 21 def metrics @metrics ||= METRIC_DESCRIPTIONS.each_with_object({}) do |(name, description), result| result[name] = ::Gitlab::Metrics.gauge(:"#{METRIC_PREFIX}#{name}", description) end end |
#sample ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/gitlab/metrics/samplers/threads_sampler.rb', line 27 def sample metrics[:max_expected_threads].set({}, Gitlab::Runtime.max_threads) threads_by_name.each do |name, threads| uses_db, not_using_db = threads.partition { |thread| thread[:uses_db_connection] } set_running_threads(name, uses_db_connection: "yes", size: uses_db.size) set_running_threads(name, uses_db_connection: "no", size: not_using_db.size) end end |