Class: Fluent::StatsdOutput

Inherits:
BufferedOutput
  • Object
show all
Defined in:
lib/fluent/plugin/out_statsd.rb

Defined Under Namespace

Classes: RubyStringParser

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStatsdOutput

Returns a new instance of StatsdOutput.



23
24
25
# File 'lib/fluent/plugin/out_statsd.rb', line 23

def initialize
  super
end

Instance Attribute Details

#statsdObject (readonly)

Returns the value of attribute statsd.



21
22
23
# File 'lib/fluent/plugin/out_statsd.rb', line 21

def statsd
  @statsd
end

Instance Method Details

#configure(conf) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/fluent/plugin/out_statsd.rb', line 27

def configure(conf)
  super
  @statsd = Statsd::Batch.new(Statsd.new(host, port))
  @statsd.namespace = namespace if namespace

  if batch_byte_size
    @statsd.batch_size = nil
    @statsd.batch_byte_size = batch_byte_size
  end
  log.info(statsd)

  @metrics = conf.elements.select {|elem| elem.name == 'metric' }
  log.info(@metrics)
end

#format(tag, time, record) ⇒ Object



51
52
53
# File 'lib/fluent/plugin/out_statsd.rb', line 51

def format(tag, time, record)
  [tag, record].to_msgpack
end

#shutdownObject



46
47
48
49
# File 'lib/fluent/plugin/out_statsd.rb', line 46

def shutdown
  super
  @statsd.flush
end

#startObject



42
43
44
# File 'lib/fluent/plugin/out_statsd.rb', line 42

def start
  super
end

#write(chunk) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/fluent/plugin/out_statsd.rb', line 55

def write(chunk)
  chunk.msgpack_each do |tag, record|
    parser = RubyStringParser.new(record: record, tag: tag)

    @metrics.each do |metric|
      arg_names = %w{statsd_type statsd_key statsd_val}
      send_to_statsd(*metric.values_at(*arg_names).map {|str| parser.parse(str) })
    end
  end
  @statsd.flush
end