Class: Fluent::Plugin::DatadogStatsdOutput
- Inherits:
-
Output
- Object
- Output
- Fluent::Plugin::DatadogStatsdOutput
- Defined in:
- lib/fluent/plugin/out_datadog_statsd.rb
Instance Attribute Summary collapse
-
#statsd ⇒ Object
readonly
Returns the value of attribute statsd.
Instance Method Summary collapse
- #configure(conf) ⇒ Object
- #multi_workers_ready? ⇒ Boolean
- #shutdown ⇒ Object
- #start ⇒ Object
- #write(chunk) ⇒ Object
Instance Attribute Details
#statsd ⇒ Object (readonly)
Returns the value of attribute statsd.
36 37 38 |
# File 'lib/fluent/plugin/out_datadog_statsd.rb', line 36 def statsd @statsd end |
Instance Method Details
#configure(conf) ⇒ Object
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 71 |
# File 'lib/fluent/plugin/out_datadog_statsd.rb', line 38 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 |
#multi_workers_ready? ⇒ Boolean
118 119 120 |
# File 'lib/fluent/plugin/out_datadog_statsd.rb', line 118 def multi_workers_ready? true end |
#shutdown ⇒ Object
77 78 79 80 |
# File 'lib/fluent/plugin/out_datadog_statsd.rb', line 77 def shutdown super @statsd.close end |
#start ⇒ Object
73 74 75 |
# File 'lib/fluent/plugin/out_datadog_statsd.rb', line 73 def start super end |
#write(chunk) ⇒ Object
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 116 |
# File 'lib/fluent/plugin/out_datadog_statsd.rb', line 82 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 |