Class: MetricCollect::Metric

Inherits:
Object
  • Object
show all
Defined in:
lib/metric_collect/metric.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = nil) ⇒ Metric

Returns a new instance of Metric.



23
24
25
26
# File 'lib/metric_collect/metric.rb', line 23

def initialize(name=nil)
  @backends = Array.new
  @name = name
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/metric_collect/metric.rb', line 28

def method_missing(method_symbol, *args, &block)
  case method_symbol
  when :statsd
    @new_backend = MetricCollect::Backend::Statsd.new(args[0])
  when :graphite
    @new_backend = MetricCollect::Backend::Graphite.new(args[0])
  when :email
    @new_backend = MetricCollect::Backend::Email.new(args[0])
  else
    if @new_backend.params.has_key?(method_symbol)
      @new_backend.params[method_symbol] = args[0]
    else
      raise ArgumentError.new("No argument for #{@new_backend.class} named #{method_symbol.to_s}")
    end
    return
  end

  begin
    yield if block
  rescue => error
    MetricCollect::Log.fatal("Error loading value[#{name}::#{@new_backend.name}]", error)
  end
  @backends << @new_backend
end

Instance Attribute Details

#backendsObject (readonly)

Returns the value of attribute backends.



20
21
22
# File 'lib/metric_collect/metric.rb', line 20

def backends
  @backends
end

#nameObject

Returns the value of attribute name.



21
22
23
# File 'lib/metric_collect/metric.rb', line 21

def name
  @name
end

Instance Method Details

#send(config) ⇒ Object



53
54
55
56
57
58
# File 'lib/metric_collect/metric.rb', line 53

def send(config)
  @backends.each do |backend|
    MetricCollect::Log.info("Processing value[#{name}::#{backend.name}] sending key: #{backend.key} value: #{backend.value} to #{backend.class}")
    backend.process_metric(config)
  end
end