Class: Fluent::Plugin::CloudWatchPutOutput

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#cloudwatchObject (readonly)

Returns the value of attribute cloudwatch.



94
95
96
# File 'lib/fluent/plugin/out_cloudwatch_put.rb', line 94

def cloudwatch
  @cloudwatch
end

Instance Method Details

#configure(conf) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/fluent/plugin/out_cloudwatch_put.rb', line 96

def configure(conf)
  super

  unless !!@metric_name ^ @key_as_metric_name
    raise Fluent::ConfigError, "'Either 'metric_name'' or 'key_as_metric_name' must be set"
  end

  @dimensions.each do |d|
    unless d.key.nil? ^ d.value.nil?
      raise Fluent::ConfigError, "'Either dimensions[key]' or 'dimensions[value]' must be set"
    end

    if @use_statistic_sets && d.key
      raise Fluent::ConfigError, "If 'use_statistic_sets' is true, dimensions[key] is not supportted"
    end

    if @use_statistic_sets && @key_as_metric_name
      raise Fluent::ConfigError, "If 'use_statistic_sets' is true, 'key_as_metric_name' is not supportted"
    end
  end

  @send_all_key = false
  if @value_key.size == 1 && @value_key[0] == "*"
    @send_all_key = true
  end

  placeholder_params = "namespace=#{@namespace}/metric_name=#{@metric_name}/unit=#{@unit}/dimensions[name]=#{@dimensions.map(&:name).join(",")}/dimensions[value]=#{@dimensions.map(&:value).join(",")}"
  placeholder_validate!(:cloudwatch_put, placeholder_params)
end

#startObject



126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/fluent/plugin/out_cloudwatch_put.rb', line 126

def start
  super

  options = setup_credentials
  options[:region] = @region if @region
  options[:http_proxy] = @proxy_uri if @proxy_uri
  log.on_trace do
    options[:http_wire_trace] = true
    options[:logger] = log
  end

  @cloudwatch = Aws::CloudWatch::Client.new(options)
end

#write(chunk) ⇒ Object



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/fluent/plugin/out_cloudwatch_put.rb', line 140

def write(chunk)
  if @use_statistic_sets
    metric_data = build_statistic_metric_data(chunk)
  else
    metric_data = build_metric_data(chunk)
  end

  namespace = extract_placeholders(@namespace, chunk.)
  log.debug "Put metric to #{namespace}, count=#{metric_data.size}"
  log.on_trace do
    log.trace metric_data.to_json
  end
  @cloudwatch.put_metric_data({
    namespace: namespace,
    metric_data: metric_data,
  })
end