Module: NewRelic::Control::Configuration

Included in:
NewRelic::Control
Defined in:
lib/new_relic/control/configuration.rb

Overview

used to contain methods to look up settings from the configuration located in newrelic.yml

Instance Method Summary collapse

Instance Method Details

#[](key) ⇒ Object



74
75
76
# File 'lib/new_relic/control/configuration.rb', line 74

def [](key)
  fetch(key)
end

#[]=(key, value) ⇒ Object



78
79
80
# File 'lib/new_relic/control/configuration.rb', line 78

def []=(key, value)
  settings[key] = value
end

#apdex_tObject



86
87
88
89
# File 'lib/new_relic/control/configuration.rb', line 86

def apdex_t
  # Always initialized with a default
  fetch('apdex_t').to_f
end

#app_namesObject



159
160
161
162
163
164
165
# File 'lib/new_relic/control/configuration.rb', line 159

def app_names
  case self['app_name']
  when Array then self['app_name']
  when String then self['app_name'].split(';')
  else [ env ]
  end
end

#browser_monitoring_auto_instrument?Boolean

whether we should install the NewRelic::Rack::BrowserMonitoring middleware automatically on Rails applications

Returns:

  • (Boolean)


113
114
115
# File 'lib/new_relic/control/configuration.rb', line 113

def browser_monitoring_auto_instrument?
  fetch('browser_monitoring', {}).fetch('auto_instrument', true)
end

#capture_paramsObject



96
97
98
# File 'lib/new_relic/control/configuration.rb', line 96

def capture_params
  fetch('capture_params')
end

#developer_mode?Boolean

True if we are capturing data and displaying in /newrelic

Returns:

  • (Boolean)


106
107
108
# File 'lib/new_relic/control/configuration.rb', line 106

def developer_mode?
  fetch('developer_mode', fetch('developer'))
end

#disable_backtrace_cleanup?Boolean

Returns:

  • (Boolean)


196
197
198
# File 'lib/new_relic/control/configuration.rb', line 196

def disable_backtrace_cleanup?
  fetch('disable_backtrace_cleanup')
end

#disable_serialization=(b) ⇒ Object



124
125
126
# File 'lib/new_relic/control/configuration.rb', line 124

def disable_serialization=(b)
  self['disable_serialization'] = b
end

#disable_serialization?Boolean

Returns:

  • (Boolean)


121
122
123
# File 'lib/new_relic/control/configuration.rb', line 121

def disable_serialization?
  fetch('disable_serialization', false)
end

#dispatcherObject



156
157
158
# File 'lib/new_relic/control/configuration.rb', line 156

def dispatcher
  (self['dispatcher'] && self['dispatcher'].to_sym) || @local_env.dispatcher
end

#dispatcher_instance_idObject



152
153
154
# File 'lib/new_relic/control/configuration.rb', line 152

def dispatcher_instance_id
  self['dispatcher_instance_id'] || @local_env.dispatcher_instance_id
end

#fetch(key, default = nil) ⇒ Object



82
83
84
# File 'lib/new_relic/control/configuration.rb', line 82

def fetch(key, default=nil)
  settings.fetch(key, default)
end

#has_slow_sql_config?Boolean

Returns:

  • (Boolean)


200
201
202
# File 'lib/new_relic/control/configuration.rb', line 200

def has_slow_sql_config?
  self['slow_sql'] && self['slow_sql'].has_key?('enabled')
end

#license_keyObject



91
92
93
94
# File 'lib/new_relic/control/configuration.rb', line 91

def license_key
  env_setting = ENV['NEW_RELIC_LICENSE_KEY'] || ENV['NEWRELIC_LICENSE_KEY']
  fetch('license_key', env_setting)
end

#log_file_pathObject



178
179
180
# File 'lib/new_relic/control/configuration.rb', line 178

def log_file_path
  fetch('log_file_path', 'log/')
end

#merge_defaults(settings_hash) ⇒ Object



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

def merge_defaults(settings_hash)
  s = {
    'host' => 'collector.newrelic.com',
    'ssl' => false,
    'log_level' => 'info',
    'apdex_t' => 0.5
  }
  s.merge! settings_hash if settings_hash
  # monitor_daemons replaced with agent_enabled
  s['agent_enabled'] = s.delete('monitor_daemons') if s['agent_enabled'].nil? && s.include?('monitor_daemons')
  s
end

#merge_options(options, hash = self) ⇒ Object

Merge the given options into the config options. They might be a nested hash



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/new_relic/control/configuration.rb', line 38

def merge_options(options, hash=self)
  options.each do |key, val|
    case
    when key == :config then next
    when val.is_a?(Hash)
      merge_options(val, hash[key.to_s] ||= {})
    when val.nil?
      hash.delete(key.to_s)
    else
      hash[key.to_s] = val
    end
  end
end

#merge_server_side_config(data) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/new_relic/control/configuration.rb', line 52

def merge_server_side_config(data)
  remove_server_controlled_configs
  config = Hash.new
  data.each_pair do |key, value|
    if key.include?('.')
      key = key.split('.')
      config[key.first] ||= Hash.new
      config[key.first][key[1]] = value
    else
      config[key] = value
    end
  end
  merge_options(config)
end

#monitor_mode?Boolean

True if we are sending data to the server, monitoring production

Returns:

  • (Boolean)


101
102
103
# File 'lib/new_relic/control/configuration.rb', line 101

def monitor_mode?
  fetch('monitor_mode', fetch('enabled'))
end

#multi_threaded?Boolean

Returns:

  • (Boolean)


117
118
119
# File 'lib/new_relic/control/configuration.rb', line 117

def multi_threaded?
  fetch('multi_threaded')
end

#post_size_limitObject

defaults to 2MiB



134
135
136
# File 'lib/new_relic/control/configuration.rb', line 134

def post_size_limit
  fetch('post_size_limit', 2 * 1024 * 1024)
end

#remove_server_controlled_configsObject



67
68
69
70
71
72
# File 'lib/new_relic/control/configuration.rb', line 67

def remove_server_controlled_configs
  settings.delete('transaction_tracer')
  settings.delete('slow_sql')
  settings.delete('error_collector')
  settings.delete('capture_params')
end

#send_data_on_exitObject

Configuration option of the same name to indicate that we should flush data to the server on exiting. Defaults to true.



148
149
150
# File 'lib/new_relic/control/configuration.rb', line 148

def send_data_on_exit
  fetch('send_data_on_exit', true)
end

#settingsObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/new_relic/control/configuration.rb', line 6

def settings
  unless @settings
    @settings = (@yaml && merge_defaults(@yaml[env])) || {}
    # At the time we bind the settings, we also need to run this little piece
    # of magic which allows someone to augment the id with the app name, necessary
    if self['multi_homed'] && app_names.size > 0
      if @local_env.dispatcher_instance_id
        @local_env.dispatcher_instance_id << ":#{app_names.first}"
      else
        @local_env.dispatcher_instance_id = app_names.first
      end
    end

  end
  @settings
end

#sync_startupObject

Configuration option of the same name to indicate that we should connect to New Relic synchronously on startup. This means when the agent is loaded it won’t return without trying to set up the server connection at least once which can make startup take longer. Defaults to false.



142
143
144
# File 'lib/new_relic/control/configuration.rb', line 142

def sync_startup
  fetch('sync_startup', false)
end

#use_ssl?Boolean

Returns:

  • (Boolean)


173
174
175
176
# File 'lib/new_relic/control/configuration.rb', line 173

def use_ssl?
  @use_ssl = fetch('ssl', false) unless @use_ssl
  @use_ssl
end

#use_textmate?Boolean

True if we should view files in textmate

Returns:

  • (Boolean)


129
130
131
# File 'lib/new_relic/control/configuration.rb', line 129

def use_textmate?
  fetch('textmate')
end

#validate_seedObject



166
167
168
# File 'lib/new_relic/control/configuration.rb', line 166

def validate_seed
  self['validate_seed'] || ENV['NR_VALIDATE_SEED']
end

#validate_tokenObject



169
170
171
# File 'lib/new_relic/control/configuration.rb', line 169

def validate_token
  self['validate_token'] || ENV['NR_VALIDATE_TOKEN']
end

#verify_certificate?Boolean

only verify certificates if you’re very sure you want this level of security, it includes possibly app-crashing dns lookups every connection to the server

Returns:

  • (Boolean)


185
186
187
188
189
190
191
192
193
194
# File 'lib/new_relic/control/configuration.rb', line 185

def verify_certificate?
  unless @verify_certificate
    unless use_ssl?
      @verify_certificate = false
    else
      @verify_certificate = fetch('verify_certificate', false)
    end
  end
  @verify_certificate
end