class Fluent::DogstatsdOutput
Attributes
statsd[RW]
Public Class Methods
new()
click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_dogstatsd.rb, line 21 def initialize super require 'datadog/statsd' # dogstatsd-ruby end
Public Instance Methods
format(tag, time, record)
click to toggle source
# File lib/fluent/plugin/out_dogstatsd.rb, line 36 def format(tag, time, record) [tag, time, record].to_msgpack end
start()
click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_dogstatsd.rb, line 27 def start super host = @host || '127.0.0.1' port = @port || 8125 @statsd ||= Datadog::Statsd.new(host, port) end
write(chunk)
click to toggle source
# File lib/fluent/plugin/out_dogstatsd.rb, line 40 def write(chunk) @statsd.batch do |s| chunk.msgpack_each do |tag, time, record| key = if @use_tag_as_key tag else record.delete('key') end if !key && @use_tag_as_key_if_missing key = tag end unless key log.warn "'key' is not specified. skip this record:", tag: tag next end value = record.delete(@value_key || 'value') options = {} title = record.delete('title') text = record.delete('text') type = @metric_type || record.delete('type') sample_rate = @sample_rate || record.delete('sample_rate') if sample_rate options[:sample_rate] = sample_rate end tags = if @flat_tags || @flat_tag record else record['tags'] end if tags options[:tags] = tags.map do |k, v| "#{k}:#{v}" end end case type when 'increment' s.increment(key, options) when 'decrement' s.decrement(key, options) when 'count' s.count(key, value, options) when 'gauge' s.gauge(key, value, options) when 'histogram' s.histogram(key, value, options) when 'timing' s.timing(key, value, options) when 'set' s.set(key, value, options) when 'event' options[:alert_type] = record['alert_type'] s.event(title, text, options) when nil log.warn "type is not provided (You can provide type via `metric_type` in config or `type` field in a record." else log.warn "Type '#{type}' is unknown." end end end end