Class: RailsAutoscaleAgent::Reporter
- Inherits:
-
Object
- Object
- RailsAutoscaleAgent::Reporter
- Includes:
- Logger, Singleton
- Defined in:
- lib/rails_autoscale_agent/reporter.rb
Class Method Summary collapse
Instance Method Summary collapse
Methods included from Logger
Class Method Details
.start(config, store) ⇒ Object
14 15 16 |
# File 'lib/rails_autoscale_agent/reporter.rb', line 14 def self.start(config, store) instance.start!(config, store) unless instance.started? end |
Instance Method Details
#start!(config, store) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rails_autoscale_agent/reporter.rb', line 18 def start!(config, store) @started = true @worker_adapters = config.worker_adapters.select(&:enabled?) @dyno_num = config.dyno.to_s.split('.').last.to_i if !config.api_base_url && !config.dev_mode? logger.info "Reporter not started: #{config.addon_name}_URL is not set" return end Thread.new do loop do register!(config, @worker_adapters) unless @registered # Stagger reporting to spread out reports from many processes multiplier = 1 - (rand / 4) # between 0.75 and 1.0 sleep config.report_interval * multiplier # It's redundant to report worker metrics from every web dyno, so only report from web.1 if @dyno_num == 1 @worker_adapters.map do |adapter| report_exceptions(config) { adapter.collect!(store) } end end report_exceptions(config) { report!(config, store) } end end end |
#started? ⇒ Boolean
48 49 50 |
# File 'lib/rails_autoscale_agent/reporter.rb', line 48 def started? @started end |