Class: AWS::Cloudwatch::Base
- 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
- #api_version ⇒ Object
- #default_host ⇒ Object
-
#get_metric_statistics(options = {}) ⇒ Object
get_metric_statistics pulls a hashed array from Cloudwatch with the stats of your requested metric.
-
#list_metrics ⇒ Object
This method call lists available Cloudwatch metrics attached to your EC2 account.
Methods inherited from Base
#extract_user_data, #initialize
Constructor Details
This class inherits a constructor from AWS::Base
Instance Method Details
#api_version ⇒ Object
20 21 22 |
# File 'lib/AWS/Cloudwatch.rb', line 20 def api_version API_VERSION end |
#default_host ⇒ Object
24 25 26 |
# File 'lib/AWS/Cloudwatch.rb', line 24 def default_host DEFAULT_HOST end |
#get_metric_statistics(options = {}) ⇒ Object
get_metric_statistics pulls a hashed array from Cloudwatch with the stats of your requested metric. Once you get the data out, if you assign the results into an object like: res = @mon.get_metric_statistics(:measure_name => ‘RequestCount’, \
:statistics => 'Average', :namespace => 'AWS/ELB')
This call gets the average request count against your ELB at each sampling period for the last 24 hours. You can then attach a block to the following iterator to do whatever you need to: res[‘Datapoints’].each
> provided options
35 36 37 38 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 83 84 85 86 87 88 |
# File 'lib/AWS/Cloudwatch/monitoring.rb', line 35 def get_metric_statistics ( ={} ) = { :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() raise ArgumentError, ":end_time must be provided" if [:end_time].nil? raise ArgumentError, ":end_time must be a Time object" if [:end_time].class != Time raise ArgumentError, ":start_time must be provided" if [:start_time].nil? raise ArgumentError, ":start_time must be a Time object" if [:start_time].class != Time raise ArgumentError, ":start_time must be before :end_time" if [:start_time] > [:end_time] raise ArgumentError, ":measure_name must be provided" if [:measure_name].nil? || [:measure_name].empty? raise ArgumentError, ":statistics must be provided" if [:statistics].nil? || [:statistics].empty? params = { "CustomUnit" => [:custom_unit], "EndTime" => [:end_time].iso8601, "MeasureName" => [:measure_name], "Namespace" => [:namespace], "Period" => [:period].to_s, "StartTime" => [:start_time].iso8601, "Unit" => [:unit] } # FDT: Fix statistics and dimensions values if !([:statistics].nil? || [:statistics].empty?) stats_params = {} i = 1 [:statistics].split(',').each{ |stat| stats_params.merge!( "Statistics.member.#{i}" => "#{stat}" ) i += 1 } params.merge!( stats_params ) end if !([:dimensions].nil? || [:dimensions].empty?) dims_params = {} i = 1 [:dimensions].split(',').each{ |dimension| dimension_var = dimension.split('=') dims_params = dims_params.merge!( "Dimensions.member.#{i}.Name" => "#{dimension_var[0]}", "Dimensions.member.#{i}.Value" => "#{dimension_var[1]}" ) i += 1 } params.merge!( dims_params ) end return response_generator(:action => 'GetMetricStatistics', :params => params) end |
#list_metrics ⇒ Object
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.
10 11 12 |
# File 'lib/AWS/Cloudwatch/monitoring.rb', line 10 def list_metrics return response_generator(:action => 'ListMetrics', :params => {}) end |