Module: MetricsCapacitor::Config

Extended by:
Config
Included in:
Config
Defined in:
lib/metrics-capacitor/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



51
52
53
54
55
56
57
58
# File 'lib/metrics-capacitor/config.rb', line 51

def method_missing (name, *args, &block)
  return @_cfg[name.to_sym] if @_cfg[name.to_sym] != nil
  fail(NoMethodError, "Unknown configuration section Config.#{name}", caller)
rescue NoMethodError => e
  $stderr.puts "ERROR config: #{e.class}: #{e.message}"
  $stderr.puts e.backtrace.map { |l| "ERROR config: #{l}\n" }.join
  exit! 1
end

Instance Attribute Details

#_cfgObject (readonly)

Returns the value of attribute _cfg.



13
14
15
# File 'lib/metrics-capacitor/config.rb', line 13

def _cfg
  @_cfg
end

Instance Method Details

#load!Object



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
# File 'lib/metrics-capacitor/config.rb', line 15

def load!
  @_cfg = {
    syslog: false,
    debug: false,
    redis: {
      url: 'redis://127.0.0.1:6379/0',
      timeout: 5,
    },
    elasticsearch: {
      urls: ['http://localhost:9200/'],
      index: 'metrics',
      timeout: 10,
      connections: 2,
    },
    scrubber: {
      threads: 4,
      processes: 2,
      retry: 3,
      tags: {}
    },
    writer: {
      processes: 2,
      doc_type: 'actual',
      bulk_max: 5000,
      bulk_wait: 10,
      ttl: '1w'
    },
    aggregator: {
      doc_type: 'aggregated',
      aggregate_by: 600, # seconds
      optimize_indices: true,
    }
  }
  @_cfg = @_cfg.deep_merge YAML.load_file('/etc/metrics-capacitor.yaml') if File.exists? '/etc/metrics-capacitor.yaml'
end