Sha256: 5f7839830e19580f1f6d5afa90305f7c98eff199202ba02be66e58258ff71278

Contents?: true

Size: 1.45 KB

Versions: 22

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_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

22 entries across 22 versions & 5 rubygems

Version Path
vagrant-cloudstack-1.1.0 vendor/bundle/gems/fog-1.22.1/lib/fog/aws/models/cloud_watch/metrics.rb
fog-aws-0.1.1 lib/fog/aws/models/cloud_watch/metrics.rb
fog-aws-0.1.0 lib/fog/aws/models/cloud_watch/metrics.rb
fog-aws-0.0.8 lib/fog/aws/models/cloud_watch/metrics.rb
fog-aws-0.0.7 lib/fog/aws/models/cloud_watch/metrics.rb
fog-aws-0.0.6 lib/fog/aws/models/cloud_watch/metrics.rb
fog-aws-0.0.5 lib/fog/aws/models/cloud_watch/metrics.rb
fog-1.26.0 lib/fog/aws/models/cloud_watch/metrics.rb
fog-1.25.0 lib/fog/aws/models/cloud_watch/metrics.rb
nsidc-fog-1.24.1 lib/fog/aws/models/cloud_watch/metrics.rb
fog-1.24.0 lib/fog/aws/models/cloud_watch/metrics.rb
ns-fog-1.22.11 lib/fog/aws/models/cloud_watch/metrics.rb
ns-fog-1.22.10 lib/fog/aws/models/cloud_watch/metrics.rb
ns-fog-1.22.9 lib/fog/aws/models/cloud_watch/metrics.rb
ns-fog-1.22.8 lib/fog/aws/models/cloud_watch/metrics.rb
ns-fog-1.22.7 lib/fog/aws/models/cloud_watch/metrics.rb
ns-fog-1.22.6 lib/fog/aws/models/cloud_watch/metrics.rb
fog-1.23.0 lib/fog/aws/models/cloud_watch/metrics.rb
ns-fog-1.22.4 lib/fog/aws/models/cloud_watch/metrics.rb
ns-fog-1.22.3 lib/fog/aws/models/cloud_watch/metrics.rb