Class: Metriksd::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/metriksd/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



10
11
12
13
# File 'lib/metriksd/config.rb', line 10

def initialize
  @servers   = []
  @reporters = []
end

Instance Attribute Details

#reportersObject (readonly)

Returns the value of attribute reporters.



8
9
10
# File 'lib/metriksd/config.rb', line 8

def reporters
  @reporters
end

#serversObject (readonly)

Returns the value of attribute servers.



8
9
10
# File 'lib/metriksd/config.rb', line 8

def servers
  @servers
end

Instance Method Details

#joinObject



61
62
63
64
65
# File 'lib/metriksd/config.rb', line 61

def join
  (@servers + @reporters).each do |t|
    t.join
  end
end

#load(config) ⇒ Object



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
# File 'lib/metriksd/config.rb', line 19

def load(config)
  config = config.with_indifferent_access

  registries = [ config[:registry] ].flatten.compact
  if registries.respond_to?(:to_hash)
    registries = registries.to_hash.values
  end

  registries.each do |registry_config|
    registry_config = registry_config.with_indifferent_access

    reporter_config = registry_config.delete(:reporter)
    unless reporter_config
      raise ArgumentError, "Must provide a 'reporter'"
    end
    reporter_config = reporter_config.with_indifferent_access

    server_config = registry_config.delete(:server)
    unless server_config
      raise "Must provide a 'server'"
    end
    server_config = server_config.with_indifferent_access

    registry = Metriksd::Registry.new(registry_config)

    @reporters << reporter_class(reporter_config.delete(:type)).new(registry, reporter_config)
    @servers   << server_class(server_config.delete(:type)).new(registry, server_config)
  end
end

#load_file(file) ⇒ Object



15
16
17
# File 'lib/metriksd/config.rb', line 15

def load_file(file)
  load(YAML::load_file(file).with_indifferent_access)
end

#reporter_class(type) ⇒ Object



67
68
69
70
71
72
73
74
75
76
# File 'lib/metriksd/config.rb', line 67

def reporter_class(type)
  case type.to_s
  when 'librato_metrics'
    Metriksd::LibratoMetricsReporter
  when '', nil
    raise "No reporter 'type' was specified"
  else
    raise "Unknown reporter 'type': #{type.inspect}"
  end
end

#server_class(type) ⇒ Object



78
79
80
81
82
83
84
85
86
87
# File 'lib/metriksd/config.rb', line 78

def server_class(type)
  case type.to_s
  when 'udp'
    Metriksd::UdpServer
  when '', nil
    raise "No server 'type' was specified"
  else
    raise "Unknown server 'type': #{type.inspect}"
  end
end

#startObject



49
50
51
52
53
# File 'lib/metriksd/config.rb', line 49

def start
  (@servers + @reporters).each do |t|
    t.start
  end
end

#stopObject



55
56
57
58
59
# File 'lib/metriksd/config.rb', line 55

def stop
  (@servers + @reporters).each do |t|
    t.stop
  end
end