Skip to content
Browse files

Applies patch from fred-secludit in Issue #23 for AWS CloudWatch.

  • Loading branch information...
1 parent 0e50731 commit 686e41200c2d79047ab1f4dd632e2b73e95a16e0 @grempe committed
Showing with 23 additions and 7 deletions.
  1. +1 −0 ChangeLog
  2. +22 −7 lib/AWS/Cloudwatch/monitoring.rb
View
1 ChangeLog
@@ -12,6 +12,7 @@
* Use HmacSHA256 signatures instead of SHA1 (preferred by AWS and improves support for Eucalyptus)
* added AWS::EC2::Base#get_password_data for GetPasswordData API (Windows instances)
* Fix #26. Raise an exception immediately if the response is a 5xx Server Error.
+ * Applied experimental CloudWatch Monitoring Patch by fred-secludit, removes limitations on which server to connect to, and better handles statistics and dimensions.
=== 0.9.16 2010-07-07
* Less strict checking on which server endpoints you can pass in as an environment var.
View
29 lib/AWS/Cloudwatch/monitoring.rb
@@ -7,9 +7,7 @@ class Base < AWS::Base
# call get_metric_statistics.
#
# there are no options available to this method.
-
def list_metrics
- raise ArgumentError, "Server must be monitoring.amazonaws.com" if server != 'monitoring.amazonaws.com'
return response_generator(:action => 'ListMetrics', :params => {})
end
@@ -34,8 +32,6 @@ def list_metrics
# @option options [String] :statistics (nil) The statistics to be returned for your metric. See the developer guide for valid options. Required.
# @option options [Time] :start_time (Time.now() - 86400) Inner bound of the date range you want to view. Defaults to 24 hours ago
# @option options [String] :unit (nil) Standard unit for a given Measure. See the developer guide for valid options.
-
-
def get_metric_statistics ( options ={} )
options = { :custom_unit => nil,
:dimensions => nil,
@@ -51,23 +47,42 @@ def get_metric_statistics ( options ={} )
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],
- "Dimensions" => options[:dimensions],
"EndTime" => options[:end_time].iso8601,
"MeasureName" => options[:measure_name],
"Namespace" => options[:namespace],
"Period" => options[:period].to_s,
- "Statistics.member.1" => options[:statistics],
"StartTime" => options[:start_time].iso8601,
"Unit" => options[:unit]
}
+ # FDT: Fix statistics and dimensions values
+ if !(options[:statistics].nil? || options[:statistics].empty?)
+ stats_params = {}
+ i = 1
+ options[:statistics].split(',').each{ |stat|
+ stats_params.merge!( "Statistics.member.#{i}" => "#{stat}" )
+ i += 1
+ }
+ params.merge!( stats_params )
+ end
+
+ if !(options[:dimensions].nil? || options[:dimensions].empty?)
+ dims_params = {}
+ i = 1
+ options[: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

0 comments on commit 686e412

Please sign in to comment.
Something went wrong with that request. Please try again.