Module: CloudWatchMetrics::Util

Defined in:
lib/cloud_watch_metrics/util.rb

Constant Summary collapse

MAX_METRIC_DATA_PER_PUT =
20

Class Method Summary collapse

Class Method Details

.accept_hash(option_parser) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/cloud_watch_metrics/util.rb', line 13

def accept_hash(option_parser)
  option_parser.accept(Hash) do |s,|
    break s unless s
    s
      .split(',').reject(&:empty?)
      .map { |kv| kv.include?('=') ? kv.split('=', 2) : [kv, true] }
      .to_h
  end
end

.put_metric_data(namespace, metric_data, dryrun: false) ⇒ void

This method returns an undefined value.



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/cloud_watch_metrics/util.rb', line 24

def put_metric_data(namespace, metric_data, dryrun: false)
  return dump_metric_data(namespace, metric_data) if dryrun

  metric_data.each_slice(MAX_METRIC_DATA_PER_PUT).map do |data|
    Thread.start(data, cloudwatch) do |data_, cloudwatch_|
      cloudwatch_.put_metric_data(
        namespace: namespace,
        metric_data: data_,
      )
    end
  end.each(&:join)
end