Class: Librato::Rack::Configuration
- Inherits:
-
Object
- Object
- Librato::Rack::Configuration
- 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.
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
-
#api_endpoint ⇒ Object
Returns the value of attribute api_endpoint.
-
#autorun ⇒ Object
Returns the value of attribute autorun.
-
#deprecations ⇒ Object
readonly
Returns the value of attribute deprecations.
-
#disable_rack_metrics ⇒ Object
Returns the value of attribute disable_rack_metrics.
-
#flush_interval ⇒ Object
Returns the value of attribute flush_interval.
-
#log_level ⇒ Object
Returns the value of attribute log_level.
-
#log_prefix ⇒ Object
Returns the value of attribute log_prefix.
-
#log_target ⇒ Object
Returns the value of attribute log_target.
-
#prefix ⇒ Object
Returns the value of attribute prefix.
-
#proxy ⇒ Object
Returns the value of attribute proxy.
-
#suites ⇒ Object
Returns the value of attribute suites.
-
#tags ⇒ Object
Returns the value of attribute tags.
-
#token ⇒ Object
Returns the value of attribute token.
-
#tracker ⇒ Object
Returns the value of attribute tracker.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
- #dump ⇒ Object
- #event_mode ⇒ Object
-
#event_mode=(mode) ⇒ Object
set event_mode, valid options are EVENT_MODES or nil (the default) if not running in an evented context.
- #has_tags? ⇒ Boolean
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#load_configuration ⇒ Object
check environment variables and capture current state for configuration.
- #metric_suites ⇒ Object
- #register_listener(listener) ⇒ Object
Constructor Details
#initialize ⇒ Configuration
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_endpoint ⇒ Object
Returns the value of attribute api_endpoint.
17 18 19 |
# File 'lib/librato/rack/configuration.rb', line 17 def api_endpoint @api_endpoint end |
#autorun ⇒ Object
Returns the value of attribute autorun.
17 18 19 |
# File 'lib/librato/rack/configuration.rb', line 17 def autorun @autorun end |
#deprecations ⇒ Object (readonly)
Returns the value of attribute deprecations.
21 22 23 |
# File 'lib/librato/rack/configuration.rb', line 21 def deprecations @deprecations end |
#disable_rack_metrics ⇒ Object
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_interval ⇒ Object
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_level ⇒ Object
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_prefix ⇒ Object
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_target ⇒ Object
Returns the value of attribute log_target.
17 18 19 |
# File 'lib/librato/rack/configuration.rb', line 17 def log_target @log_target end |
#prefix ⇒ Object
Returns the value of attribute prefix.
21 22 23 |
# File 'lib/librato/rack/configuration.rb', line 21 def prefix @prefix end |
#proxy ⇒ Object
Returns the value of attribute proxy.
17 18 19 |
# File 'lib/librato/rack/configuration.rb', line 17 def proxy @proxy end |
#suites ⇒ Object
Returns the value of attribute suites.
17 18 19 |
# File 'lib/librato/rack/configuration.rb', line 17 def suites @suites end |
#tags ⇒ Object
Returns the value of attribute tags.
17 18 19 |
# File 'lib/librato/rack/configuration.rb', line 17 def @tags end |
#token ⇒ Object
Returns the value of attribute token.
17 18 19 |
# File 'lib/librato/rack/configuration.rb', line 17 def token @token end |
#tracker ⇒ Object
Returns the value of attribute tracker.
17 18 19 |
# File 'lib/librato/rack/configuration.rb', line 17 def tracker @tracker end |
#user ⇒ Object
Returns the value of attribute user.
17 18 19 |
# File 'lib/librato/rack/configuration.rb', line 17 def user @user end |
Instance Method Details
#dump ⇒ Object
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_mode ⇒ Object
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
51 52 53 |
# File 'lib/librato/rack/configuration.rb', line 51 def @tags && !@tags.empty? end |
#load_configuration ⇒ Object
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. = 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_suites ⇒ Object
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 |