Class: Neetodeploy::Sidekiq::MetricsCollector
- Inherits:
-
Object
- Object
- Neetodeploy::Sidekiq::MetricsCollector
- Includes:
- NeetoDeploy::Logger, Singleton
- Defined in:
- lib/neetodeploy/autoscale/sidekiq/metrics_collector.rb
Class Method Summary collapse
Instance Method Summary collapse
- #run_sidekiq_metrics_collection ⇒ Object
- #running? ⇒ Boolean
- #start! ⇒ Object
- #start_thread_with_collector_loop(config = Config.instance) ⇒ Object
- #stop! ⇒ Object
Methods included from NeetoDeploy::Logger
Class Method Details
.start ⇒ Object
15 16 17 |
# File 'lib/neetodeploy/autoscale/sidekiq/metrics_collector.rb', line 15 def self.start instance.start! unless instance.running? end |
Instance Method Details
#run_sidekiq_metrics_collection ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/neetodeploy/autoscale/sidekiq/metrics_collector.rb', line 54 def run_sidekiq_metrics_collection return unless sidekiq_available? return if Config.instance.sidekiq_metrics_disabled? begin queues = ::Sidekiq::Queue.all return if queues.empty? queues.each do |queue| collect_queue_metrics(queue) end rescue StandardError => e logger.error("Error collecting Sidekiq metrics: #{e.message}") end end |
#running? ⇒ Boolean
31 32 33 |
# File 'lib/neetodeploy/autoscale/sidekiq/metrics_collector.rb', line 31 def running? @pid == Process.pid and @thread&.alive? end |
#start! ⇒ Object
19 20 21 22 23 |
# File 'lib/neetodeploy/autoscale/sidekiq/metrics_collector.rb', line 19 def start! logger.info("Starting Sidekiq metrics collector") @pid = Process.pid start_thread_with_collector_loop end |
#start_thread_with_collector_loop(config = Config.instance) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/neetodeploy/autoscale/sidekiq/metrics_collector.rb', line 35 def start_thread_with_collector_loop(config = Config.instance) @thread = Thread.new do loop do run_sidekiq_metrics_collection multiplier = 1 - (rand / 4) sleep config.report_interval_seconds * multiplier end rescue StandardError => e logger.error("Sidekiq metrics collector thread terminated with error: #{e.message}") logger.error(e.backtrace.join("\n")) if e.backtrace ensure if @pid == Process.pid && !@thread.nil? logger.info("Restarting Sidekiq metrics collector thread") sleep(5) start_thread_with_collector_loop end end end |
#stop! ⇒ Object
25 26 27 28 29 |
# File 'lib/neetodeploy/autoscale/sidekiq/metrics_collector.rb', line 25 def stop! @pid = nil # Set pid to nil first to prevent restart @thread&.terminate @thread = nil end |