Top Level Namespace

Defined Under Namespace

Modules: Cloudscopes

Instance Method Summary collapse

Instance Method Details

#publish(samples) ⇒ Object

public API expressed through kernel (global) methods, for simplicity



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/cloudscopes/globals.rb', line 5

def publish(samples)
  raise "Not running in EC2, so won't publish!" unless File.executable?("/usr/bin/ec2metadata")
  samples.each do |type,metric_samples|
    begin
      valid_data = metric_samples.select(&:valid)
      next if valid_data.empty?
      valid_data.each_slice(4) do |slice| # slice metrics to chunks - the actual limit is 20, but CloudWatch starts misbehaving if I put too much data
        Cloudscopes.client.put_metric_data namespace: type,
                                          metric_data: slice.collect(&:to_cloudwatch_metric_data)
      end
    rescue Exception => e
      puts "Error publishing metrics for #{type}: #{e}"
    end
  end
end

#sample(category, *metrics) ⇒ Object



21
22
23
24
25
# File 'lib/cloudscopes/globals.rb', line 21

def sample(category, *metrics)
  category, metrics = category if category.is_a? Array # sample may be passed the single yield variable of Hash#each
  metrics = [ metrics ] unless metrics.is_a? Array
  [ category, metrics.collect { |m| Cloudscopes::Sample.new(category, m) } ]
end