Class: MetricCollect::Backend::Statsd

Inherits:
Object
  • Object
show all
Defined in:
lib/backend/statsd.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Statsd



23
24
25
26
27
28
29
# File 'lib/backend/statsd.rb', line 23

def initialize(name)
  @params = Hash.new
  @params[:name] = name
  @params[:value] = nil
  @params[:key] = "metric_collect"
  @params[:type] = :gauge
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



31
32
33
# File 'lib/backend/statsd.rb', line 31

def method_missing(method_symbol, *args, &block)
  @params[method_symbol]
end

Instance Attribute Details

#paramsObject

Returns the value of attribute params.



35
36
37
# File 'lib/backend/statsd.rb', line 35

def params
  @params
end

Instance Method Details

#process_metric(config) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/backend/statsd.rb', line 37

def process_metric(config)
  @config = config.params
  name = @params[:name]
  value = @params[:value]
  key = @params[:key]
  type = @params[:type]

  case type
  when :counter
    counters("#{key}.#{name}", value)
  when :timer
    timers("#{key}.#{name}", value)
  when :gauge
    gauges("#{key}.#{name}", value)
  when :set
    sets("#{key}.#{name}", value)
  else
    MetricCollect::Log.fatal("#{type.to_s} is not a valid statsd type!")
  end
end