Class: Librato::Rack::Configuration
- Inherits:
-
Object
- Object
- Librato::Rack::Configuration
- Defined in:
- lib/librato/rack/configuration.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.
Constant Summary collapse
- EVENT_MODES =
[:eventmachine, :synchrony]
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.
-
#source ⇒ Object
Returns the value of attribute source.
-
#source_pids ⇒ Object
Returns the value of attribute source_pids.
-
#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.
- #explicit_source? ⇒ Boolean
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#load_configuration ⇒ Object
check environment variables and capture current state for configuration.
- #register_listener(listener) ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/librato/rack/configuration.rb', line 20 def initialize # set up defaults self.tracker = nil self.api_endpoint = Librato::Metrics.api_endpoint self.flush_interval = 60 self.source_pids = false self.log_prefix = '[librato-rack] ' @listeners = [] @deprecations = [] load_configuration end |
Instance Attribute Details
#api_endpoint ⇒ Object
Returns the value of attribute api_endpoint.
15 16 17 |
# File 'lib/librato/rack/configuration.rb', line 15 def api_endpoint @api_endpoint end |
#autorun ⇒ Object
Returns the value of attribute autorun.
15 16 17 |
# File 'lib/librato/rack/configuration.rb', line 15 def autorun @autorun end |
#deprecations ⇒ Object (readonly)
Returns the value of attribute deprecations.
18 19 20 |
# File 'lib/librato/rack/configuration.rb', line 18 def deprecations @deprecations end |
#disable_rack_metrics ⇒ Object
Returns the value of attribute disable_rack_metrics.
15 16 17 |
# File 'lib/librato/rack/configuration.rb', line 15 def disable_rack_metrics @disable_rack_metrics end |
#flush_interval ⇒ Object
Returns the value of attribute flush_interval.
15 16 17 |
# File 'lib/librato/rack/configuration.rb', line 15 def flush_interval @flush_interval end |
#log_level ⇒ Object
Returns the value of attribute log_level.
15 16 17 |
# File 'lib/librato/rack/configuration.rb', line 15 def log_level @log_level end |
#log_prefix ⇒ Object
Returns the value of attribute log_prefix.
15 16 17 |
# File 'lib/librato/rack/configuration.rb', line 15 def log_prefix @log_prefix end |
#log_target ⇒ Object
Returns the value of attribute log_target.
15 16 17 |
# File 'lib/librato/rack/configuration.rb', line 15 def log_target @log_target end |
#prefix ⇒ Object
Returns the value of attribute prefix.
18 19 20 |
# File 'lib/librato/rack/configuration.rb', line 18 def prefix @prefix end |
#source ⇒ Object
Returns the value of attribute source.
18 19 20 |
# File 'lib/librato/rack/configuration.rb', line 18 def source @source end |
#source_pids ⇒ Object
Returns the value of attribute source_pids.
15 16 17 |
# File 'lib/librato/rack/configuration.rb', line 15 def source_pids @source_pids end |
#token ⇒ Object
Returns the value of attribute token.
15 16 17 |
# File 'lib/librato/rack/configuration.rb', line 15 def token @token end |
#tracker ⇒ Object
Returns the value of attribute tracker.
15 16 17 |
# File 'lib/librato/rack/configuration.rb', line 15 def tracker @tracker end |
#user ⇒ Object
Returns the value of attribute user.
15 16 17 |
# File 'lib/librato/rack/configuration.rb', line 15 def user @user end |
Instance Method Details
#dump ⇒ Object
80 81 82 83 84 85 86 |
# File 'lib/librato/rack/configuration.rb', line 80 def dump fields = {} %w{user token log_level source prefix flush_interval source_pids}.each do |field| fields[field.to_sym] = self.send(field) end fields end |
#event_mode ⇒ Object
33 34 35 |
# File 'lib/librato/rack/configuration.rb', line 33 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
39 40 41 42 43 44 45 46 47 |
# File 'lib/librato/rack/configuration.rb', line 39 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 |
#explicit_source? ⇒ Boolean
49 50 51 |
# File 'lib/librato/rack/configuration.rb', line 49 def explicit_source? !!@explicit_source end |
#load_configuration ⇒ Object
check environment variables and capture current state for configuration
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/librato/rack/configuration.rb', line 55 def load_configuration self.user = ENV['LIBRATO_USER'] || ENV['LIBRATO_METRICS_USER'] self.token = ENV['LIBRATO_TOKEN'] || ENV['LIBRATO_METRICS_TOKEN'] self.autorun = detect_autorun self.prefix = ENV['LIBRATO_PREFIX'] || ENV['LIBRATO_METRICS_PREFIX'] self.source = ENV['LIBRATO_SOURCE'] || ENV['LIBRATO_METRICS_SOURCE'] self.log_level = ENV['LIBRATO_LOG_LEVEL'] || :info self.event_mode = ENV['LIBRATO_EVENT_MODE'] check_deprecations end |
#register_listener(listener) ⇒ Object
71 72 73 |
# File 'lib/librato/rack/configuration.rb', line 71 def register_listener(listener) @listeners << listener end |