class PumaCloudwatch::Metrics::Looper
Public Class Methods
new(options)
click to toggle source
# File lib/puma_cloudwatch/metrics/looper.rb, line 7 def initialize(options) @options = options @control_url = options[:control_url] @control_auth_token = options[:control_auth_token] @frequency = Integer(ENV['PUMA_CLOUDWATCH_FREQUENCY'] || 60) @enabled = ENV['PUMA_CLOUDWATCH_ENABLED'] || false end
run(options)
click to toggle source
# File lib/puma_cloudwatch/metrics/looper.rb, line 3 def self.run(options) new(options).run end
Public Instance Methods
message()
click to toggle source
# File lib/puma_cloudwatch/metrics/looper.rb, line 23 def message message = "puma-cloudwatch plugin: Will send data every #{@frequency} seconds." unless @enabled to_enable = "To enable set the environment variable PUMA_CLOUDWATCH_ENABLED=1" message = "Disabled: #{message}\n#{to_enable}" end message end
run()
click to toggle source
# File lib/puma_cloudwatch/metrics/looper.rb, line 15 def run raise StandardError, "Puma control app is not activated" if @control_url == nil puts(message) unless ENV['PUMA_CLOUDWATCH_MUTE_START_MESSAGE'] Thread.new do perform end end
Private Instance Methods
enabled?()
click to toggle source
# File lib/puma_cloudwatch/metrics/looper.rb, line 46 def enabled? !!@enabled end
perform()
click to toggle source
# File lib/puma_cloudwatch/metrics/looper.rb, line 33 def perform loop do begin stats = Fetcher.new(@options).call results = Parser.new(stats).call Sender.new(results).call unless results.empty? sleep @frequency rescue Exception => e puts "Error reached top of looper: #{e.message} (#{e.class})" end end end