Class: Fluent::Plugin::DatadogStatsdOutput

Inherits:
Output
  • Object
show all
Defined in:
lib/fluent/plugin/out_datadog_statsd.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#statsdObject (readonly)

Returns the value of attribute statsd.



35
36
37
# File 'lib/fluent/plugin/out_datadog_statsd.rb', line 35

def statsd
  @statsd
end

Instance Method Details

#configure(conf) ⇒ Object



37
38
39
40
41
42
43
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
# File 'lib/fluent/plugin/out_datadog_statsd.rb', line 37

def configure(conf)
  super

  placeholder_params = [
    @metric_type,
    @tags
  ]

  if @metric_config
    placeholder_params += [
      @metric_config.name,
      @metric_config.value
    ]
  end
  if @event_config
    placeholder_params += [
      @event_config.title,
      @event_config.text,
      @event_config.aggregation_key,
      @event_config.alert_type,
      @event_config.priority,
      @event_config.source_type_name,
      @event_config.date_happened
    ]
  end

  placeholder_validate!(:placeholder_params, placeholder_params.join('/'))

  require 'datadog/statsd'
  @host ||= Datadog::Statsd::DEFAULT_HOST
  @port ||= Datadog::Statsd::DEFAULT_PORT

  @statsd = Datadog::Statsd.new(@host, @port)
end

#shutdownObject



76
77
78
79
# File 'lib/fluent/plugin/out_datadog_statsd.rb', line 76

def shutdown
  super
  @statsd.close
end

#startObject



72
73
74
# File 'lib/fluent/plugin/out_datadog_statsd.rb', line 72

def start
  super
end

#write(chunk) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/fluent/plugin/out_datadog_statsd.rb', line 81

def write(chunk)
   = chunk.
  metric_type = extract_placeholders(@metric_type, ).to_sym

  @statsd.batch do |statsd|
    statsd_param = case metric_type
                   when :increment, :decrement
                     if @metric_config.nil?
                       log.error("metric section is required when metric_type=#{metric_type}")
                       return nil
                     end
                     extract_placeholders_name_opt()

                   when :count, :gauge, :histgram, :timing, :set
                     if @metric_config.nil?
                       log.error("metric section is required when metric_type=#{metric_type}")
                       return nil
                     end
                     extract_placeholders_name_value_opt()
                   when :event
                     if @event_config.nil?
                       log.error('event section is required when metric_type=event')
                       return nil
                     end
                     extract_placeholders_event()
                   else
                     log.error("param 'metric_type=#{metric_type}' is illegal.")
                     return nil
                   end
    statsd_func = statsd.method(metric_type)
    chunk.each do |_time, _record|
      statsd_func.call(*statsd_param)
    end
  end
end