Class: RightAws::Mon
- Inherits:
-
RightAwsBase
- Object
- RightAwsBase
- RightAws::Mon
- Includes:
- RightAwsBaseInterface
- 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 =
RightAws::AwsBenchmarkingBlock.new
- @@api =
Current API version (sometimes we have to check it outside the GEM).
ENV['EC2_API_VERSION'] || API_VERSION
Constants included from RightAwsBaseInterface
RightAwsBaseInterface::DEFAULT_SIGNATURE_VERSION
Constants inherited from RightAwsBase
Instance Attribute Summary
Attributes included from RightAwsBaseInterface
#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, period = 60, dimensions = nil, custom_unit = nil, namespace = "AWS/EC2") ⇒ 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 startTime : Timestamp to start endtime: Timestamp to end unit: Either Seconds, Percent, Bytes, Bits, Count, Bytes, Bits/Second, Count/Second, and None period: Integer 60 or multiple of 60 dimension: Hash containing keys ImageId, AutoScalingGroupName, InstanceId, InstanceType customUnit: nil.
-
#initialize(aws_access_key_id = nil, aws_secret_access_key = nil, params = {}) ⇒ Mon
constructor
A new instance of Mon.
-
#list_metrics ⇒ Object
—————————————————————– REQUESTS —————————————————————–.
-
#request_info(request, parser) ⇒ Object
Sends request to Amazon and parses the response Raises AwsError if any banana happened.
Methods included from RightAwsBaseInterface
#cache_hits?, caching, caching=, #caching?, #init, #multi_thread, #on_exception, #request_cache_or_info, #request_info_impl, #signed_service_params, #update_cache
Methods inherited from RightAwsBase
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 |
# 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 }, 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
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 |
# File 'lib/ec2/right_mon_interface.rb', line 48 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, period = 60, dimensions = nil, custom_unit = nil, namespace = "AWS/EC2") ⇒ 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 startTime : Timestamp to start endtime: Timestamp to end unit: Either Seconds, Percent, Bytes, Bits, Count, Bytes, Bits/Second, Count/Second, and None period: Integer 60 or multiple of 60 dimension: Hash containing keys ImageId, AutoScalingGroupName, InstanceId, InstanceType customUnit: nil. not supported currently. namespace: AWS/EC2
116 117 118 119 120 121 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 |
# File 'lib/ec2/right_mon_interface.rb', line 116 def get_metric_statistics ( measure_name, stats, start_time, end_time, unit, period=60, dimensions=nil, custom_unit=nil, 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 @logger.info("get Metric Statistics ") link = generate_request("GetMetricStatistics", params) resp = request_info(link, QMonGetMetricStatistics.new(:logger => @logger)) rescue Exception on_exception end |
#list_metrics ⇒ Object
REQUESTS
91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/ec2/right_mon_interface.rb', line 91 def list_metrics params = { } @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
81 82 83 84 85 |
# File 'lib/ec2/right_mon_interface.rb', line 81 def request_info(request, parser) thread = @params[:multi_thread] ? Thread.current : Thread.main thread[:elb_connection] ||= Rightscale::HttpConnection.new(:exception => RightAws::AwsError, :logger => @logger) request_info_impl(thread[:elb_connection], @@bench, request, parser) end |