Class: PumaCloudwatch::Metrics::Looper

Inherits:
Object
  • Object
show all
Defined in:
lib/puma_cloudwatch/metrics/looper.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Looper

Returns a new instance of Looper.



7
8
9
10
11
12
13
14
# 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
  @fetched = false
end

Class Method Details

.run(options) ⇒ Object



3
4
5
# File 'lib/puma_cloudwatch/metrics/looper.rb', line 3

def self.run(options)
  new(options).run
end

Instance Method Details

#messageObject



24
25
26
27
28
29
30
31
# File 'lib/puma_cloudwatch/metrics/looper.rb', line 24

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

#runObject

Raises:

  • (StandardError)


16
17
18
19
20
21
22
# File 'lib/puma_cloudwatch/metrics/looper.rb', line 16

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