Class: MetricSense::Collector

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Collector

Returns a new instance of Collector.



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/metricsense.rb', line 60

def initialize(config)
  @config = config
  tag_prefix = @config['tag_prefix']
  @event_prefix = @config['event_prefix'] || 'metricsense.event'
  @metric_prefix = @config['metric_prefix'] || 'metricsense.metric'
  opts = {}
  opts[:host] = @config['host'] if @config['host']
  opts[:port] = @config['port'] if @config['port']
  @logger = Fluent::Logger::FluentLogger.new(tag_prefix, opts)
  #@logger = Fluent::Logger::ConsoleLogger.new(STDOUT)
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



72
73
74
# File 'lib/metricsense.rb', line 72

def config
  @config
end

Instance Method Details

#measure(e) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
# File 'lib/metricsense.rb', line 74

def measure(e)
  record = e.facts.merge(e.segments).merge!(e.values)
  @logger.post_with_time("#{@event_prefix}.#{e.tag}", record, e.time)

  values = {:count=>1}.merge!(e.values)
  values.each_pair {|k,v|
    tag = "#{@metric_prefix}.#{e.tag}.#{k}"
    record = e.segments.merge(:value=>v)
    @logger.post_with_time(tag, record, e.time)
  }
end