Class: Librato::Rack::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/librato/rack/configuration.rb,
lib/librato/rack/configuration/suites.rb

Overview

Holds configuration for Librato::Rack middleware to use. Acquires some settings by default from environment variables, but this allows easy setting and overrides.

Examples:

config = Librato::Rack::Configuration.new
config.user  = '[email protected]'
config.token = 'mytoken'

Defined Under Namespace

Classes: Suites, SuitesAll, SuitesNone

Constant Summary collapse

EVENT_MODES =
[:eventmachine, :synchrony]
DEFAULT_SUITES =
[:rack, :rack_method, :rack_status]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/librato/rack/configuration.rb', line 23

def initialize
  # set up defaults
  self.tracker = nil
  self.api_endpoint = Librato::Metrics.api_endpoint
  self.flush_interval = 60
  self.log_prefix = '[librato-rack] '
  @listeners = []
  @deprecations = []

  load_configuration
end

Instance Attribute Details

#api_endpointObject

Returns the value of attribute api_endpoint.



17
18
19
# File 'lib/librato/rack/configuration.rb', line 17

def api_endpoint
  @api_endpoint
end

#autorunObject

Returns the value of attribute autorun.



17
18
19
# File 'lib/librato/rack/configuration.rb', line 17

def autorun
  @autorun
end

#deprecationsObject (readonly)

Returns the value of attribute deprecations.



21
22
23
# File 'lib/librato/rack/configuration.rb', line 21

def deprecations
  @deprecations
end

#disable_rack_metricsObject

Returns the value of attribute disable_rack_metrics.



17
18
19
# File 'lib/librato/rack/configuration.rb', line 17

def disable_rack_metrics
  @disable_rack_metrics
end

#flush_intervalObject

Returns the value of attribute flush_interval.



17
18
19
# File 'lib/librato/rack/configuration.rb', line 17

def flush_interval
  @flush_interval
end

#log_levelObject

Returns the value of attribute log_level.



17
18
19
# File 'lib/librato/rack/configuration.rb', line 17

def log_level
  @log_level
end

#log_prefixObject

Returns the value of attribute log_prefix.



17
18
19
# File 'lib/librato/rack/configuration.rb', line 17

def log_prefix
  @log_prefix
end

#log_targetObject

Returns the value of attribute log_target.



17
18
19
# File 'lib/librato/rack/configuration.rb', line 17

def log_target
  @log_target
end

#prefixObject

Returns the value of attribute prefix.



21
22
23
# File 'lib/librato/rack/configuration.rb', line 21

def prefix
  @prefix
end

#proxyObject

Returns the value of attribute proxy.



17
18
19
# File 'lib/librato/rack/configuration.rb', line 17

def proxy
  @proxy
end

#suitesObject

Returns the value of attribute suites.



17
18
19
# File 'lib/librato/rack/configuration.rb', line 17

def suites
  @suites
end

#tagsObject

Returns the value of attribute tags.



17
18
19
# File 'lib/librato/rack/configuration.rb', line 17

def tags
  @tags
end

#tokenObject

Returns the value of attribute token.



17
18
19
# File 'lib/librato/rack/configuration.rb', line 17

def token
  @token
end

#trackerObject

Returns the value of attribute tracker.



17
18
19
# File 'lib/librato/rack/configuration.rb', line 17

def tracker
  @tracker
end

#userObject

Returns the value of attribute user.



17
18
19
# File 'lib/librato/rack/configuration.rb', line 17

def user
  @user
end

Instance Method Details

#dumpObject



79
80
81
82
83
84
85
86
# File 'lib/librato/rack/configuration.rb', line 79

def dump
  fields = {}
  %w{flush_interval log_level prefix suites tags token user}.each do |field|
    fields[field.to_sym] = self.send(field)
  end
  fields[:metric_suites] = metric_suites.fields
  fields
end

#event_modeObject



35
36
37
# File 'lib/librato/rack/configuration.rb', line 35

def event_mode
  @event_mode
end

#event_mode=(mode) ⇒ Object

set event_mode, valid options are EVENT_MODES or nil (the default) if not running in an evented context



41
42
43
44
45
46
47
48
49
# File 'lib/librato/rack/configuration.rb', line 41

def event_mode=(mode)
  mode = mode.to_sym if mode
  # reject unless acceptable mode, allow for turning event_mode off
  if [*EVENT_MODES, nil].include?(mode)
    @event_mode = mode
  else
    # TODO log warning
  end
end

#has_tags?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/librato/rack/configuration.rb', line 51

def has_tags?
  @tags && !@tags.empty?
end

#load_configurationObject

check environment variables and capture current state for configuration



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/librato/rack/configuration.rb', line 57

def load_configuration
  self.user = ENV['LIBRATO_USER']
  self.token = ENV['LIBRATO_TOKEN']
  self.autorun = detect_autorun
  self.prefix = ENV['LIBRATO_PREFIX']
  self.tags = build_tags
  self.log_level = ENV['LIBRATO_LOG_LEVEL'] || :info
  self.proxy = ENV['LIBRATO_PROXY'] || ENV['https_proxy'] || ENV['http_proxy']
  self.event_mode = ENV['LIBRATO_EVENT_MODE']
  self.suites = ENV['LIBRATO_SUITES'] || ''
  check_deprecations
end

#metric_suitesObject



88
89
90
91
92
93
94
95
96
97
# File 'lib/librato/rack/configuration.rb', line 88

def metric_suites
  @metric_suites ||= case suites.downcase.strip
                     when 'all'
                       SuitesAll.new
                     when 'none'
                       SuitesNone.new
                     else
                       Suites.new(suites, default_suites)
                     end
end

#register_listener(listener) ⇒ Object



75
76
77
# File 'lib/librato/rack/configuration.rb', line 75

def register_listener(listener)
  @listeners << listener
end