Sha256: 97a05b70117c9e80896b323465f3864fa416c8ca33bff6b610f713e96392e049

Contents?: true

Size: 1.45 KB

Versions: 65

Compression:

Stored size: 1.45 KB

Contents

require 'fog/core/collection'
require 'fog/aws/models/cloud_watch/metric'

module Fog
  module AWS
    class CloudWatch

      class Metrics < Fog::Collection
        attribute :next_token, :aliases => 'NextToken'

        model Fog::AWS::CloudWatch::Metric

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

        alias :each_metric_this_page :each
        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

        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

      end
    end
  end
end

Version data entries

65 entries across 65 versions & 6 rubygems

Version Path
fog-1.22.0 lib/fog/aws/models/cloud_watch/metrics.rb
fog-1.21.0 lib/fog/aws/models/cloud_watch/metrics.rb
fog-maestrodev-1.20.0.20140305101839 lib/fog/aws/models/cloud_watch/metrics.rb
fog-maestrodev-1.20.0.20140305101305 lib/fog/aws/models/cloud_watch/metrics.rb
fog-maestrodev-1.19.0.20140212012611 lib/fog/aws/models/cloud_watch/metrics.rb
fog-1.20.0 lib/fog/aws/models/cloud_watch/metrics.rb
fog-maestrodev-1.19.0.20140110004459 lib/fog/aws/models/cloud_watch/metrics.rb
fog-maestrodev-1.19.0.20140110003812 lib/fog/aws/models/cloud_watch/metrics.rb
fog-maestrodev-1.19.0.20140109202555 lib/fog/aws/models/cloud_watch/metrics.rb
fog-maestrodev-1.19.0.20140107192102 lib/fog/aws/models/cloud_watch/metrics.rb
fog-maestrodev-1.19.0.20140107142106 lib/fog/aws/models/cloud_watch/metrics.rb
fog-maestrodev-1.19.0.20131219203941 lib/fog/aws/models/cloud_watch/metrics.rb
fog-maestrodev-1.18.0.20131219193542 lib/fog/aws/models/cloud_watch/metrics.rb
fog-1.19.0 lib/fog/aws/models/cloud_watch/metrics.rb
fog-maestrodev-1.18.0.20131219033443 lib/fog/aws/models/cloud_watch/metrics.rb
fog-maestrodev-1.18.0.20131219032002 lib/fog/aws/models/cloud_watch/metrics.rb
fog-maestrodev-1.18.0.20131219030716 lib/fog/aws/models/cloud_watch/metrics.rb
fog-maestrodev-1.18.0.20131219022322 lib/fog/aws/models/cloud_watch/metrics.rb
fog-maestrodev-1.18.0.20131218202447 lib/fog/aws/models/cloud_watch/metrics.rb
fog-maestrodev-1.18.0.20131209091424 lib/fog/aws/models/cloud_watch/metrics.rb