Class: Aws::Mon
- Includes:
- AwsBaseInterface
- Defined in:
- lib/ec2/right_mon_interface.rb
Defined Under Namespace
Classes: QMonGetMetricStatistics, QMonListMetrics
Constant Summary collapse
- API_VERSION =
Amazon EC2 API version being used
"2009-05-15"
- DEFAULT_HOST =
"monitoring.amazonaws.com"
- DEFAULT_PATH =
'/'
- DEFAULT_PROTOCOL =
'https'
- DEFAULT_PORT =
443
- @@bench =
Aws::AwsBenchmarkingBlock.new
- @@api =
Current API version (sometimes we have to check it outside the GEM).
ENV['EC2_API_VERSION'] || API_VERSION
Constants included from AwsBaseInterface
AwsBaseInterface::DEFAULT_SIGNATURE_VERSION
Constants inherited from AwsBase
Instance Attribute Summary
Attributes included from AwsBaseInterface
#aws_access_key_id, #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
-
#get_metric_statistics(measure_name, stats, start_time, end_time, unit, options = {}) ⇒ Object
measureName: CPUUtilization (Units: Percent), NetworkIn (Units: Bytes), NetworkOut (Units: Bytes), DiskWriteOps (Units: Count) DiskReadBytes (Units: Bytes), DiskReadOps (Units: Count), DiskWriteBytes (Units: Bytes) stats: array containing one or more of Minimum, Maximum, Sum, Average, Samples start_time : Timestamp to start end_time: Timestamp to end unit: Either Seconds, Percent, Bytes, Bits, Count, Bytes, Bits/Second, Count/Second, and None.
-
#initialize(aws_access_key_id = nil, aws_secret_access_key = nil, params = {}) ⇒ Mon
constructor
A new instance of Mon.
-
#list_metrics(options = {}) ⇒ Object
—————————————————————– REQUESTS —————————————————————–.
-
#request_info(request, parser) ⇒ Object
Sends request to Amazon and parses the response Raises AwsError if any banana happened.
Methods included from AwsBaseInterface
#cache_hits?, caching, caching=, #caching?, #close_conn, #generate_request2, #get_conn, #hash_params, #init, #multi_thread, #on_exception, #request_cache_or_info, #request_info2, #request_info_impl, #request_info_xml_simple, #signed_service_params, #symbolize, #update_cache
Methods inherited from AwsBase
amazon_problems, amazon_problems=
Constructor Details
#initialize(aws_access_key_id = nil, aws_secret_access_key = nil, params = {}) ⇒ Mon
Returns a new instance of Mon.
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/ec2/right_mon_interface.rb', line 36 def initialize(aws_access_key_id=nil, aws_secret_access_key=nil, params={}) init({ :name => 'MON', :default_host => ENV['MON_URL'] ? URI.parse(ENV['MON_URL']).host : DEFAULT_HOST, :default_port => ENV['MON_URL'] ? URI.parse(ENV['MON_URL']).port : DEFAULT_PORT, :default_service => ENV['MON_URL'] ? URI.parse(ENV['MON_URL']).path : DEFAULT_PATH, :default_protocol => ENV['MON_URL'] ? URI.parse(ENV['MON_URL']).scheme : DEFAULT_PROTOCOL, :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
.api ⇒ Object
31 32 33 |
# File 'lib/ec2/right_mon_interface.rb', line 31 def self.api @@api end |
.bench_ec2 ⇒ Object
24 25 26 |
# File 'lib/ec2/right_mon_interface.rb', line 24 def self.bench_ec2 @@bench.service end |
.bench_xml ⇒ Object
20 21 22 |
# File 'lib/ec2/right_mon_interface.rb', line 20 def self.bench_xml @@bench.xml end |
Instance Method Details
#generate_request(action, params = {}) ⇒ Object
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 |
# File 'lib/ec2/right_mon_interface.rb', line 49 def generate_request(action, params={}) service_hash = {"Action" => action, "AWSAccessKeyId" => @aws_access_key_id, "Version" => @@api } service_hash.update(params) service_params = signed_service_params(@aws_secret_access_key, service_hash, :get, @params[:server], @params[:service]) # use POST method if the length of the query string is too large if service_params.size > 2000 if signature_version == '2' # resign the request because HTTP verb is included into signature service_params = signed_service_params(@aws_secret_access_key, service_hash, :post, @params[:server], @params[:service]) end request = Net::HTTP::Post.new(service) request.body = service_params request['Content-Type'] = 'application/x-www-form-urlencoded' else request = Net::HTTP::Get.new("#{@params[:service]}?#{service_params}") end #puts "\n\n --------------- QUERY REQUEST TO AWS -------------- \n\n" #puts "#{@params[:service]}?#{service_params}\n\n" # prepare output hash { :request => request, :server => @params[:server], :port => @params[:port], :protocol => @params[:protocol] } end |
#get_metric_statistics(measure_name, stats, start_time, end_time, unit, options = {}) ⇒ Object
measureName: CPUUtilization (Units: Percent), NetworkIn (Units: Bytes), NetworkOut (Units: Bytes), DiskWriteOps (Units: Count)
DiskReadBytes (Units: Bytes), DiskReadOps (Units: Count), DiskWriteBytes (Units: Bytes)
stats: array containing one or more of Minimum, Maximum, Sum, Average, Samples start_time : Timestamp to start end_time: Timestamp to end unit: Either Seconds, Percent, Bytes, Bits, Count, Bytes, Bits/Second, Count/Second, and None
Optional parameters:
period: Integer 60 or multiple of 60
dimensions: Hash containing keys ImageId, AutoScalingGroupName, InstanceId, InstanceType
customUnit: nil. not supported currently.
namespace: AWS/EC2
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/ec2/right_mon_interface.rb', line 122 def get_metric_statistics ( measure_name, stats, start_time, end_time, unit, ={}) period = [:period] || 60 dimensions = [:dimensions] || nil custom_unit = [:custom_unit] || nil namespace = [:namespace] || "AWS/EC2" params = {} params['MeasureName'] = measure_name i=1 stats.each do |s| params['Statistics.member.'+i.to_s] = s i = i+1 end params['Period'] = period if (dimensions != nil) i = 1 dimensions.each do |k, v| params['Dimensions.member.'+i.to_s+".Name."+i.to_s] = k params['Dimensions.member.'+i.to_s+".Value."+i.to_s] = v i = i+1 end end params['StartTime'] = start_time params['EndTime'] = end_time params['Unit'] = unit #params['CustomUnit'] = customUnit always nil params['Namespace'] = namespace link = generate_request("GetMetricStatistics", params) resp = request_info(link, QMonGetMetricStatistics.new(:logger => @logger)) rescue Exception on_exception end |
#list_metrics(options = {}) ⇒ Object
REQUESTS
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/ec2/right_mon_interface.rb', line 92 def list_metrics(={}) next_token = [:next_token] || nil params = { } params['NextToken'] = next_token unless next_token.nil? @logger.info("list Metrics ") link = generate_request("ListMetrics", params) resp = request_info(link, QMonListMetrics.new(:logger => @logger)) rescue Exception on_exception end |
#request_info(request, parser) ⇒ Object
Sends request to Amazon and parses the response Raises AwsError if any banana happened
82 83 84 85 86 |
# File 'lib/ec2/right_mon_interface.rb', line 82 def request_info(request, parser) thread = @params[:multi_thread] ? Thread.current : Thread.main thread[:elb_connection] ||= Rightscale::HttpConnection.new(:exception => Aws::AwsError, :logger => @logger) request_info_impl(thread[:elb_connection], @@bench, request, parser) end |