Class: RightAws::AcwInterface
- Inherits:
-
RightAwsBase
- Object
- RightAwsBase
- RightAws::AcwInterface
- Includes:
- RightAwsBaseInterface
- Defined in:
- lib/acw/right_acw_interface.rb
Overview
RightAWS::AcwInterface – RightScale Amazon Cloud Watch interface
The RightAws::AcwInterface class provides a complete interface to Amazon Cloud Watch service.
For explanations of the semantics of each call, please refer to Amazon’s documentation at docs.amazonwebservices.com/AmazonCloudWatch/latest/DeveloperGuide/
Defined Under Namespace
Classes: GetMetricStatisticsParser, ListMetricsParser
Constant Summary collapse
- API_VERSION =
Amazon ACW API version being used
"2009-05-15"
- DEFAULT_HOST =
"monitoring.amazonaws.com"
- DEFAULT_PATH =
'/'
- DEFAULT_PROTOCOL =
'https'
- DEFAULT_PORT =
443
- @@bench =
AwsBenchmarkingBlock.new
Constants included from RightAwsBaseInterface
RightAwsBaseInterface::BLOCK_DEVICE_KEY_MAPPING, RightAwsBaseInterface::DEFAULT_SIGNATURE_VERSION
Constants inherited from RightAwsBase
RightAwsBase::AMAZON_PROBLEMS, RightAwsBase::RAISE_ON_TIMEOUT_ON_ACTIONS
Instance Attribute Summary
Attributes included from RightAwsBaseInterface
#aws_access_key_id, #aws_secret_access_key, #cache, #connection, #last_errors, #last_request, #last_request_id, #last_response, #logger, #params, #signature_version
Class Method Summary collapse
Instance Method Summary collapse
-
#generate_request(action, params = {}) ⇒ Object
:nodoc:.
-
#get_metric_statistics(options = {}) ⇒ Object
Get time-series data for one or more statistics of given a Metric Returns a hash of stat data.
-
#initialize(aws_access_key_id = nil, aws_secret_access_key = nil, params = {}) ⇒ AcwInterface
constructor
Create a new handle to an ACW account.
-
#list_metrics ⇒ Object
This call returns a list of the valid metrics for which there is recorded data available to a you.
-
#request_info(request, parser) ⇒ Object
Sends request to Amazon and parses the response Raises AwsError if any banana happened.
Methods included from RightAwsBaseInterface
#amazonize_block_device_mappings, #amazonize_list, #cache_hits?, caching, caching=, #caching?, #destroy_connection, #generate_request_impl, #get_connection, #get_connections_storage, #get_server_url, #incrementally_list_items, #init, #on_exception, #request_cache_or_info, #request_info_impl, #signed_service_params, #update_cache, #with_connection_options
Methods inherited from RightAwsBase
amazon_problems, amazon_problems=, raise_on_timeout_on_actions, raise_on_timeout_on_actions=
Constructor Details
#initialize(aws_access_key_id = nil, aws_secret_access_key = nil, params = {}) ⇒ AcwInterface
Create a new handle to an ACW account. All handles share the same per process or per thread HTTP connection to Amazon ACW. Each handle is for a specific account. The params have the following options:
-
:endpoint_url
a fully qualified url to Amazon API endpoint (this overwrites: :server, :port, :service, :protocol). Example: ‘monitoring.amazonaws.com/’ -
:server
: ACW service host, default: DEFAULT_HOST -
:port
: ACW service port, default: DEFAULT_PORT -
:protocol
: ‘http’ or ‘https’, default: DEFAULT_PROTOCOL -
:logger
: for log messages, default: RAILS_DEFAULT_LOGGER else STDOUT -
:signature_version
: The signature version : ‘0’,‘1’ or ‘2’(default) -
:cache
: true/false(default): list_metrics
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/acw/right_acw_interface.rb', line 61 def initialize(aws_access_key_id=nil, aws_secret_access_key=nil, params={}) init({ :name => 'ACW', :default_host => ENV['ACW_URL'] ? URI.parse(ENV['ACW_URL']).host : DEFAULT_HOST, :default_port => ENV['ACW_URL'] ? URI.parse(ENV['ACW_URL']).port : DEFAULT_PORT, :default_service => ENV['ACW_URL'] ? URI.parse(ENV['ACW_URL']).path : DEFAULT_PATH, :default_protocol => ENV['ACW_URL'] ? URI.parse(ENV['ACW_URL']).scheme : DEFAULT_PROTOCOL, :default_api_version => ENV['ACW_API_VERSION'] || API_VERSION }, aws_access_key_id || ENV['AWS_ACCESS_KEY_ID'] , aws_secret_access_key|| ENV['AWS_SECRET_ACCESS_KEY'], params) end |
Class Method Details
.bench_service ⇒ Object
46 47 48 |
# File 'lib/acw/right_acw_interface.rb', line 46 def self.bench_service @@bench.service end |
.bench_xml ⇒ Object
43 44 45 |
# File 'lib/acw/right_acw_interface.rb', line 43 def self.bench_xml @@bench.xml end |
Instance Method Details
#generate_request(action, params = {}) ⇒ Object
:nodoc:
73 74 75 |
# File 'lib/acw/right_acw_interface.rb', line 73 def generate_request(action, params={}) #:nodoc: generate_request_impl(:get, action, params ) end |
#get_metric_statistics(options = {}) ⇒ Object
Get time-series data for one or more statistics of given a Metric Returns a hash of stat data.
Options are:
:period - x*60 seconds interval (where x > 0)
:statistics - Average, Minimum. Maximum, Sum, Samples
:start_time - The timestamp of the first datapoint to return, inclusive.
:end_time - The timestamp to use for determining the last datapoint to return. This is the last datapoint to fetch, exclusive.
:namespace - The namespace corresponding to the service of interest. For example, AWS/EC2 represents Amazon EC2.
:unit - Seconds, Percent, Bytes, Bits, Count, Bytes/Second, Bits/Second, Count/Second, and None
:custom_unit - The user-defined CustomUnit applied to a Measure. Please see the key term Unit.
:dimentions
Dimensions for EC2 Metrics:
* ImageId - shows the requested metric for all instances running this EC2 Amazon Machine Image(AMI)
* AvailabilityZone - shows the requested metric for all instances running in that EC2 Availability Zone
* CapacityGroupName - shows the requested metric for all instances in the specified capacity group - this dimension is
only available for EC2 metrics when the instances are in an Amazon Automatic Scaling Service
Capacity Group
* InstanceId - shows the requested metric for only the identified instance
* InstanceType - shows the requested metric for all instances running with that instance type
* Service (required) - the name of the service that reported the monitoring data - for EC2 metrics, use "EC2"
* Namespace (required) - in private beta, the available metrics are all reported by AWS services, so set this to "AWS"
Dimensions for Load Balancing Metrics:
* AccessPointName - shows the requested metric for the specified AccessPoint name
* AvailabilityZone - shows the requested metric for all instances running in that EC2 Availability Zone
* Service (required) - the name of the service that reported the monitoring data - for LoadBalancing metrics, use "LBS"
* Namespace (required) - in private beta, the available metrics are all reported by AWS services, so set this to "AWS"
:measure_name
EC2 Metrics:
* CPUUtilization the percentage of allocated EC2 Compute Units that are currently in use on the instance. Units are Percent.
* NetworkIn - the number of bytes received on all network interfaces by the instance. Units are Bytes.
* NetworkOut - the number of bytes sent out on all network interfaces by the instance. Units are Bytes.
* DiskReadOps - completed read operations from all disks available to the instance in one minute. Units are Count/Second.
* DiskWriteOps - completed writes operations to all disks available to the instance in one minute. Units are Count/Second.
* DiskReadBytes - bytes read from all disks available to the instance in one minute. Units are Bytes/Second.
* DiskWriteBytes - bytes written to all disks available to the instance in one minute. Units are Bytes/Second.
Load Balancing Metrics:
* Latency - time taken between a request and the corresponding response as seen by the load balancer. Units are in
seconds, and the available statistics include minimum, maximum, average and count.
* RequestCount - number of requests processed by the AccessPoint over the valid period. Units are count per second, and
the available statistics include minimum, maximum and sum. A valid period can be anything equal to or
multiple of sixty (60) seconds.
* HealthyHostCount - number of healthy EndPoints for the valid Period. A valid period can be anything equal to or a multiple
of sixty (60) seconds. Units are the count of EndPoints. The meaningful statistic for HealthyHostCount
is the average for an AccessPoint within an Availability Zone. Both Load Balancing dimensions,
AccessPointName and AvailabilityZone, should be specified when retreiving HealthyHostCount.
* UnHealthyHostCount - number of unhealthy EndPoints for the valid Period. A valid period can be anything equal to or a multiple
of sixty (60) seconds. Units are the count of EndPoints. The meaningful statistic for UnHealthyHostCount
is the average for an AccessPoint within Availability Amazon Monitoring Service Developer Guide Load
Balancing Metrics Version PRIVATE BETA 2009-01-22 19 Zone. Both Load Balancing dimensions, AccessPointName
and AvailabilityZone, should be specified when retreiving UnHealthyHostCount.
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/acw/right_acw_interface.rb', line 142 def get_metric_statistics(={}) # Period (60 sec by default) period = ([:period] && [:period].to_i) || 60 # Statistics ('Average' by default) statistics = Array([:statistics]).flatten statistics = statistics.right_blank? ? ['Average'] : statistics.map{|statistic| statistic.to_s.capitalize } # Times (5.min.ago up to now by default) start_time = [:start_time] || (Time.now.utc - 5*60) start_time = start_time.utc.strftime("%Y-%m-%dT%H:%M:%S+00:00") if start_time.is_a?(Time) end_time = [:end_time] || Time.now.utc end_time = end_time.utc.strftime("%Y-%m-%dT%H:%M:%S+00:00") if end_time.is_a?(Time) # Measure name measure_name = [:measure_name] || 'CPUUtilization' # Dimentions (a hash, empty by default) dimentions = [:dimentions] || {} # request_hash = { 'Period' => period, 'StartTime' => start_time, 'EndTime' => end_time, 'MeasureName' => measure_name } request_hash['Unit'] = [:unit] if [:unit] request_hash['CustomUnit'] = [:custom_unit] if [:custom_unit] request_hash['Namespace'] = [:namespace] if [:namespace] request_hash.merge!(amazonize_list('Statistics.member', statistics)) # dimentions dim = [] dimentions.each do |key, values| Array(values).each { |value| dim << [key, value] } end request_hash.merge!(amazonize_list(['Dimensions.member.?.Name', 'Dimensions.member.?.Value'], dim)) # link = generate_request("GetMetricStatistics", request_hash) request_info(link, GetMetricStatisticsParser.new(:logger => @logger)) end |
#list_metrics ⇒ Object
This call returns a list of the valid metrics for which there is recorded data available to a you.
acw.list_metrics #=>
[ { :namespace => "AWS/ELB",
:measure_name => "HealthyHostCount",
:dimentions => { "LoadBalancerName"=>"test-kd1" } },
{ :namespace => "AWS/ELB",
:measure_name => "UnHealthyHostCount",
:dimentions => { "LoadBalancerName"=>"test-kd1" } } ]
186 187 188 189 |
# File 'lib/acw/right_acw_interface.rb', line 186 def list_metrics link = generate_request("ListMetrics") request_cache_or_info :list_metrics, link, ListMetricsParser, @@bench, true end |
#request_info(request, parser) ⇒ Object
Sends request to Amazon and parses the response Raises AwsError if any banana happened
79 80 81 |
# File 'lib/acw/right_acw_interface.rb', line 79 def request_info(request, parser) #:nodoc: request_info_impl(:ams_connection, @@bench, request, parser) end |