class Fluent::StatsdOutput
Attributes
statsd[R]
Public Class Methods
new()
click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_statsd.rb, line 25 def initialize super end
Public Instance Methods
configure(conf)
click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_statsd.rb, line 29 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)
click to toggle source
# File lib/fluent/plugin/out_statsd.rb, line 53 def format(tag, time, record) [tag, record].to_msgpack end
shutdown()
click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_statsd.rb, line 48 def shutdown super @statsd.flush end
start()
click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_statsd.rb, line 44 def start super end
write(chunk)
click to toggle source
# File lib/fluent/plugin/out_statsd.rb, line 57 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 statsd_rate} send_to_statsd(*metric.values_at(*arg_names).map {|str| parser.parse(str) }) end end @statsd.flush end
Private Instance Methods
send_to_statsd(type, key, val, rate)
click to toggle source
# File lib/fluent/plugin/out_statsd.rb, line 72 def send_to_statsd(type, key, val, rate) log.debug([type, key, val, rate]) rate = sample_rate if rate.nil? case type when 'timing' @statsd.timing key, val.to_f, rate.to_f when 'gauge' @statsd.gauge key, val.to_f, rate.to_f when 'count' @statsd.count key, val.to_f, rate.to_f when 'set' @statsd.set key, val, rate.to_f when 'increment' @statsd.increment key, rate.to_f when 'decrement' @statsd.decrement key, rate.to_f else raise "Invalid statsd type '#{type}'" end end