Class: Fluent::DdOutput

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

Instance Method Summary collapse

Constructor Details

#initializeDdOutput

Returns a new instance of DdOutput.



11
12
13
14
15
# File 'lib/fluent/plugin/out_dd.rb', line 11

def initialize
  super
  require 'dogapi'
  require 'socket'
end

Instance Method Details

#configure(conf) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/fluent/plugin/out_dd.rb', line 25

def configure(conf)
  super

  unless @dd_api_key
    raise Fluent::ConfigError, '`dd_api_key` is required'
  end

  unless @host
    @host = %x[hostname -f 2> /dev/null].strip
    @host = Socket.gethostname if @host.empty?
  end

  @dog = Dogapi::Client.new(@dd_api_key, nil, @host)
end

#format(tag, time, record) ⇒ Object



40
41
42
# File 'lib/fluent/plugin/out_dd.rb', line 40

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

#shutdownObject



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

def shutdown
  super
end

#startObject



17
18
19
# File 'lib/fluent/plugin/out_dd.rb', line 17

def start
  super
end

#write(chunk) ⇒ Object



44
45
46
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
# File 'lib/fluent/plugin/out_dd.rb', line 44

def write(chunk)
  enum = chunk.to_enum(:msgpack_each)

  enum.select {|tag, time, record|
    unless record['metric']
      log.warn("`metric` key does not exist: #{[tag, time, record].inspect}")
    end

    record['metric']
  }.chunk {|tag, time, record|
    tag = record['tag'] || tag
    [tag] + record.values_at('metric', 'host', 'type')
  }.each {|i, records|
    tag, metric, host, type = i

    points = records.map do |tag, time, record|
      time = Time.at(time)
      value = record['value']
      [time, value]
    end

    options = {}
    options['tags'] = tag.split(',').map {|i| i.strip } if tag
    options['host'] = host if host
    options['type'] = type if type

    @dog.emit_points(metric, points, options)
  }
end