Class: MetricCollect::Metric
- Inherits:
-
Object
- Object
- MetricCollect::Metric
- Defined in:
- lib/metric_collect/metric.rb
Instance Attribute Summary collapse
-
#backends ⇒ Object
readonly
Returns the value of attribute backends.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(name = nil) ⇒ Metric
constructor
A new instance of Metric.
- #method_missing(method_symbol, *args, &block) ⇒ Object
- #send(config) ⇒ Object
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
#backends ⇒ Object (readonly)
Returns the value of attribute backends.
20 21 22 |
# File 'lib/metric_collect/metric.rb', line 20 def backends @backends end |
#name ⇒ Object
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 |