Sha256: fd31b90d200e2a35eb8473311387358ab226effa84aee5d745df6549064c5ca9

Contents?: true

Size: 1.42 KB

Versions: 75

Compression:

Stored size: 1.42 KB

Contents

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_method :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.map 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

75 entries across 73 versions & 3 rubygems

Version Path
fog-aws-3.10.0 lib/fog/aws/models/cloud_watch/metrics.rb
fog-aws-3.9.0 lib/fog/aws/models/cloud_watch/metrics.rb
fog-aws-3.8.0 lib/fog/aws/models/cloud_watch/metrics.rb
fog-aws-3.7.0 lib/fog/aws/models/cloud_watch/metrics.rb
fog-aws-3.6.7 lib/fog/aws/models/cloud_watch/metrics.rb
fog-aws-3.6.6 lib/fog/aws/models/cloud_watch/metrics.rb
fog-aws-3.6.5 lib/fog/aws/models/cloud_watch/metrics.rb
fog-aws-3.6.4 lib/fog/aws/models/cloud_watch/metrics.rb
fog-aws-3.6.3 lib/fog/aws/models/cloud_watch/metrics.rb
fog-aws-3.6.2 lib/fog/aws/models/cloud_watch/metrics.rb
fog-aws-3.5.2 lib/fog/aws/models/cloud_watch/metrics.rb
fog-aws-3.5.1 lib/fog/aws/models/cloud_watch/metrics.rb
fog-aws-3.5.0 lib/fog/aws/models/cloud_watch/metrics.rb
fog-aws-3.4.0 lib/fog/aws/models/cloud_watch/metrics.rb
fog-aws-3.3.0 lib/fog/aws/models/cloud_watch/metrics.rb
fog-aws-3.2.0 lib/fog/aws/models/cloud_watch/metrics.rb
fog-aws-3.1.0 lib/fog/aws/models/cloud_watch/metrics.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.3.0/gems/fog-aws-2.0.1/lib/fog/aws/models/cloud_watch/metrics.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.5.0/gems/fog-aws-2.0.1/lib/fog/aws/models/cloud_watch/metrics.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/fog-aws-2.0.1/lib/fog/aws/models/cloud_watch/metrics.rb