Class: Neetodeploy::Rails::MetricsCollector
- Inherits:
-
Object
- Object
- Neetodeploy::Rails::MetricsCollector
- Includes:
- NeetoDeploy::Logger, Singleton
- Defined in:
- lib/neetodeploy/autoscale/rails/metrics_collector.rb
Class Method Summary collapse
Instance Method Summary collapse
- #run_metrics_collection(metrics_store) ⇒ 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
14 15 16 |
# File 'lib/neetodeploy/autoscale/rails/metrics_collector.rb', line 14 def self.start instance.start! unless instance.running? end |
Instance Method Details
#run_metrics_collection(metrics_store) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/neetodeploy/autoscale/rails/metrics_collector.rb', line 45 def run_metrics_collection(metrics_store) data = metrics_store.flush return if data.empty? average_queue_time = data.sum / data.size Reporter.new(average_queue_time, "queue_time", "web").report end |
#running? ⇒ Boolean
30 31 32 |
# File 'lib/neetodeploy/autoscale/rails/metrics_collector.rb', line 30 def running? @pid == Process.pid and @thread.alive? end |
#start! ⇒ Object
18 19 20 21 22 |
# File 'lib/neetodeploy/autoscale/rails/metrics_collector.rb', line 18 def start! logger.info("Starting background worker to collect metrics") @pid = Process.pid start_thread_with_collector_loop end |
#start_thread_with_collector_loop(config = Config.instance) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/neetodeploy/autoscale/rails/metrics_collector.rb', line 34 def start_thread_with_collector_loop(config = Config.instance) @thread = Thread.new do metrics_store = MetricsStore.instance loop do run_metrics_collection(metrics_store) multiplier = 1 - (rand / 4) sleep config.report_interval_seconds * multiplier end end end |
#stop! ⇒ Object
24 25 26 27 28 |
# File 'lib/neetodeploy/autoscale/rails/metrics_collector.rb', line 24 def stop! @thread&.terminate @thread = nil @pid = nil end |