Class: NewRelic::Agent::Configuration::YamlSource

Inherits:
DottedHash
  • Object
show all
Defined in:
lib/new_relic/agent/configuration/yaml_source.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from DottedHash

#inspect, #to_hash

Constructor Details

#initialize(path, env) ⇒ YamlSource

Returns a new instance of YamlSource.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/new_relic/agent/configuration/yaml_source.rb', line 13

def initialize(path, env)
  ::NewRelic::Agent.logger.info("Reading configuration from #{path}")

  config = {}
  begin
    @file_path = File.expand_path(path)
    if !File.exists?(@file_path)
      ::NewRelic::Agent.logger.error("Unable to load configuration from #{path}")
      return
    end

    file = File.read(@file_path)

    # Next two are for populating the newrelic.yml via erb binding, necessary
    # when using the default newrelic.yml file
    generated_for_user = ''
    license_key = ''

    erb = ERB.new(file).result(binding)
    confighash = with_yaml_engine { YAML.load(erb) }
    ::NewRelic::Agent.logger.error("Config (#{path}) doesn't include a '#{env}' environment!") unless
      confighash.key?(env)

    config = merge!(confighash[env] || {})
  rescue ScriptError, StandardError => e
    ::NewRelic::Agent.logger.error("Unable to read configuration file #{path}: #{e}")
  end

  if config['transaction_tracer'] &&
      config['transaction_tracer']['transaction_threshold'] =~ /apdex_f/i
    # when value is "apdex_f" remove the config and defer to default
    config['transaction_tracer'].delete('transaction_threshold')
  end

  booleanify_values(config, 'agent_enabled', 'enabled', 'monitor_daemons')

  super(config)
end

Instance Attribute Details

#file_pathObject

Returns the value of attribute file_path.



11
12
13
# File 'lib/new_relic/agent/configuration/yaml_source.rb', line 11

def file_path
  @file_path
end