Class: AWS::Cloudwatch::Base

Inherits:
Base
  • Object
show all
Defined in:
lib/AWS/Cloudwatch.rb,
lib/AWS/Cloudwatch/monitoring.rb

Instance Attribute Summary

Attributes inherited from Base

#port, #proxy_server, #server, #use_ssl

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from AWS::Base

Instance Method Details

#api_versionObject



22
23
24
# File 'lib/AWS/Cloudwatch.rb', line 22

def api_version
  API_VERSION
end

#default_hostObject



26
27
28
# File 'lib/AWS/Cloudwatch.rb', line 26

def default_host
  DEFAULT_HOST
end

#get_metric_statistics(options = {}) ⇒ Object

Raises:



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/AWS/Cloudwatch/monitoring.rb', line 39

def get_metric_statistics ( options ={} )
  options = { :custom_unit => nil,
              :dimensions => nil,
              :end_time => Time.now(),      #req
              :measure_name => "",          #req
              :namespace => "AWS/EC2",
              :period => 60,
              :statistics => "",            # req
              :start_time => (Time.now() - 86400), # Default to yesterday
              :unit => "" }.merge(options)

  raise ArgumentError, ":end_time must be provided" if options[:end_time].nil?
  raise ArgumentError, ":end_time must be a Time object" if options[:end_time].class != Time
  raise ArgumentError, ":start_time must be provided" if options[:start_time].nil?
  raise ArgumentError, ":start_time must be a Time object" if options[:start_time].class != Time
  raise ArgumentError, "Server must be monitoring.amazonaws.com" if server != 'monitoring.amazonaws.com'
  raise ArgumentError, ":start_time must be before :end_time" if options[:start_time] > options[:end_time]
  raise ArgumentError, ":measure_name must be provided" if options[:measure_name].nil? || options[:measure_name].empty?
  raise ArgumentError, ":statistics must be provided" if options[:statistics].nil? || options[:statistics].empty?

  params = {
              "CustomUnit" => options[:custom_unit],
              "EndTime" => options[:end_time].iso8601,
              "MeasureName" => options[:measure_name],
              "Namespace" => options[:namespace],
              "Period" => options[:period].to_s,
              "StartTime" => options[:start_time].iso8601,
              "Unit" => options[:unit]
  }

  options[:statistics].each_index do |x|
    params['Statistics.member.' + (x + 1).to_s] = options[:statistics][x]
  end

  index = 1
  options[:dimensions].each_pair do |k, v|
    params['Dimensions.member.' + index.to_s + '.Name'] = k
    params['Dimensions.member.' + index.to_s + '.Value'] = v
    index += 1
  end

  return response_generator(:action => 'GetMetricStatistics', :params => params)

end

#list_metricsObject

This method call lists available Cloudwatch metrics attached to your EC2 account. To get further information from the metrics, you’ll then need to call get_metric_statistics.

there are no options available to this method.

Raises:



11
12
13
14
# File 'lib/AWS/Cloudwatch/monitoring.rb', line 11

def list_metrics
  raise ArgumentError, "Server must be monitoring.amazonaws.com" if server != 'monitoring.amazonaws.com'
  return response_generator(:action => 'ListMetrics', :params => {})
end