Class: Fluent::MetricSenseOutput::Backends::DatadogBackend
- Inherits:
-
Fluent::MetricSenseOutput::Backend
- Object
- Fluent::MetricSenseOutput::Backend
- Fluent::MetricSenseOutput::Backends::DatadogBackend
- Defined in:
- lib/fluent/plugin/backends/datadog_backend.rb
Constant Summary
Constants inherited from Fluent::MetricSenseOutput::Backend
Fluent::MetricSenseOutput::Backend::UpdateMode
Instance Attribute Summary
Attributes inherited from Fluent::MetricSenseOutput::Backend
Instance Method Summary collapse
- #configure(conf) ⇒ Object
-
#initialize ⇒ DatadogBackend
constructor
A new instance of DatadogBackend.
- #write(data) ⇒ Object
Methods inherited from Fluent::MetricSenseOutput::Backend
Constructor Details
#initialize ⇒ DatadogBackend
Returns a new instance of DatadogBackend.
31 32 33 34 |
# File 'lib/fluent/plugin/backends/datadog_backend.rb', line 31 def initialize() super require "dogapi" end |
Instance Method Details
#configure(conf) ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# 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) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# 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 metric_points.each do |metric, segment_points| segment_points.each do |segment, points| = @tags.dup if segment and not segment.empty? .push(segment) end = {} [:tags] = [:host] = @host if @host [:type] = "gauge" log.debug("datadog emit points: metric=#{metric}, points=#{points.inspect}, options=#{.inspect}") begin code, response = @dog.emit_points(metric, points, ) rescue Exception => error # dogapi may raise an Exception. # fluentd expects StandardError as retriable error, though. raise("datadog error: #{error.class}: #{error.}") end if code.to_i / 100 != 2 raise("datadog error: HTTP #{code}: #{response.inspect}") end end end end end |