class Fluent::MetricSenseOutput::Backends::DatadogBackend
Public Class Methods
new()
click to toggle source
Calls superclass method
# File lib/fluent/plugin/backends/datadog_backend.rb, line 31 def initialize() super require "dogapi" end
Public Instance Methods
configure(conf)
click to toggle source
Calls superclass method
# File lib/fluent/plugin/backends/datadog_backend.rb, line 36 def configure(conf) super if @dd_api_key.nil? raise Fluent::ConfigError, "missing Datadog API key" end silent = false # raise exceptions on dogapi errors @dog = Dogapi::Client.new(@dd_api_key, @dd_app_key, @host, @device, silent, @timeout) end
write(data)
click to toggle source
# File lib/fluent/plugin/backends/datadog_backend.rb, line 47 def write(data) data.each_slice(@batch_size) do |slice| metric_points = {} slice.each do |tag, time, value, seg_key, seg_val| if seg_key and seg_val # segmented values metric = "#{tag}_by_#{seg_key}" segment = "#{seg_key}:#{seg_val}" else # simple values metric = tag segment = "" end metric_points[metric] ||= {} metric_points[metric][segment] ||= [] metric_points[metric][segment].push([Time.at(time), value]) end begin log.debug("sending #{metric_points.length} metric(s) to datadog...") @dog.batch_metrics do metric_points.each do |metric, segment_points| segment_points.each do |segment, points| tags = @tags.dup if segment and not segment.empty? tags.push(segment) end options = {} options[:tags] = tags options[:host] = @host if @host options[:type] = "gauge" @dog.emit_points(metric, points, options) end end end rescue Exception => error # dogapi may raise an Exception. # fluentd expects StandardError as retriable error, though. raise("datadog error: #{error.class}: #{error.message}") end end end