Class: Fog::AWS::CloudWatch::Metrics

Inherits:
Collection
  • Object
show all
Defined in:
lib/fog/aws/models/cloud_watch/metrics.rb

Instance Attribute Summary

Attributes inherited from Collection

#service

Instance Method Summary collapse

Methods inherited from Collection

#clear, #create, #destroy, #initialize, #inspect, #load, model, #model, #new, #reload, #table, #to_json

Methods included from Fog::Attributes::ClassMethods

#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes

Methods included from Core::DeprecatedConnectionAccessors

#connection, #connection=, #prepare_service_value

Methods included from Fog::Attributes::InstanceMethods

#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #persisted?, #requires, #requires_one

Constructor Details

This class inherits a constructor from Fog::Collection

Instance Method Details

#all(conditions = {}) ⇒ Object



13
14
15
16
17
# File 'lib/fog/aws/models/cloud_watch/metrics.rb', line 13

def all(conditions={})
  result = service.list_metrics(conditions).body['ListMetricsResult']
  merge_attributes("NextToken" => result["NextToken"])
  load(result['Metrics']) # an array of attribute hashes
end

#eachObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/fog/aws/models/cloud_watch/metrics.rb', line 20

def each
  if !block_given?
    self
  else
    subset = dup.all
    subset.each_metric_this_page {|m| yield m }

    while next_token = subset.next_token
      subset = subset.all("NextToken" => next_token)
      subset.each_metric_this_page {|m| yield m }
    end

    self
  end
end

#each_metric_this_pageObject



19
# File 'lib/fog/aws/models/cloud_watch/metrics.rb', line 19

alias :each_metric_this_page :each

#get(namespace, metric_name, dimensions = nil) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/fog/aws/models/cloud_watch/metrics.rb', line 36

def get(namespace, metric_name, dimensions=nil)
  list_opts = {'Namespace' => namespace, 'MetricName' => metric_name}
  if dimensions
    dimensions_array = dimensions.collect do |name, value|
      {'Name' => name, 'Value' => value}
    end
    # list_opts.merge!('Dimensions' => dimensions_array)
  end
  if data = service.list_metrics(list_opts).body['ListMetricsResult']['Metrics'].first
    new(data)
  end
end