appoxy-aws 1.11.34 → 1.11.35
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/awsbase/right_awsbase.rb +759 -702
- data/lib/ec2/right_mon_interface.rb +222 -0
- data/lib/sdb/active_sdb.rb +1 -0
- data/lib/sdb/right_sdb_interface.rb +5 -2
- metadata +3 -2
@@ -0,0 +1,222 @@
|
|
1
|
+
module RightAws
|
2
|
+
|
3
|
+
class Mon < RightAws::RightAwsBase
|
4
|
+
include RightAws::RightAwsBaseInterface
|
5
|
+
|
6
|
+
|
7
|
+
#Amazon EC2 API version being used
|
8
|
+
API_VERSION = "2009-05-15"
|
9
|
+
DEFAULT_HOST = "monitoring.amazonaws.com"
|
10
|
+
DEFAULT_PATH = '/'
|
11
|
+
DEFAULT_PROTOCOL = 'https'
|
12
|
+
DEFAULT_PORT = 443
|
13
|
+
|
14
|
+
# Available measures for EC2 instances:
|
15
|
+
# NetworkIn NetworkOut DiskReadOps DiskWriteOps DiskReadBytes DiskWriteBytes CPUUtilization
|
16
|
+
measures=%w(NetworkIn NetworkOut DiskReadOps DiskWriteOps DiskReadBytes DiskWriteBytes CPUUtilization)
|
17
|
+
|
18
|
+
@@bench = RightAws::AwsBenchmarkingBlock.new
|
19
|
+
def self.bench_xml
|
20
|
+
@@bench.xml
|
21
|
+
end
|
22
|
+
def self.bench_ec2
|
23
|
+
@@bench.service
|
24
|
+
end
|
25
|
+
|
26
|
+
# Current API version (sometimes we have to check it outside the GEM).
|
27
|
+
@@api = ENV['EC2_API_VERSION'] || API_VERSION
|
28
|
+
def self.api
|
29
|
+
@@api
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
def initialize(aws_access_key_id=nil, aws_secret_access_key=nil, params={})
|
34
|
+
init({ :name => 'MON',
|
35
|
+
:default_host => ENV['MON_URL'] ? URI.parse(ENV['MON_URL']).host : DEFAULT_HOST,
|
36
|
+
:default_port => ENV['MON_URL'] ? URI.parse(ENV['MON_URL']).port : DEFAULT_PORT,
|
37
|
+
:default_service => ENV['MON_URL'] ? URI.parse(ENV['MON_URL']).path : DEFAULT_PATH,
|
38
|
+
:default_protocol => ENV['MON_URL'] ? URI.parse(ENV['MON_URL']).scheme : DEFAULT_PROTOCOL },
|
39
|
+
aws_access_key_id || ENV['AWS_ACCESS_KEY_ID'],
|
40
|
+
aws_secret_access_key|| ENV['AWS_SECRET_ACCESS_KEY'],
|
41
|
+
params)
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
def generate_request(action, params={})
|
46
|
+
service_hash = {"Action" => action,
|
47
|
+
"AWSAccessKeyId" => @aws_access_key_id,
|
48
|
+
"Version" => @@api }
|
49
|
+
service_hash.update(params)
|
50
|
+
service_params = signed_service_params(@aws_secret_access_key, service_hash, :get, @params[:server], @params[:service])
|
51
|
+
|
52
|
+
# use POST method if the length of the query string is too large
|
53
|
+
if service_params.size > 2000
|
54
|
+
if signature_version == '2'
|
55
|
+
# resign the request because HTTP verb is included into signature
|
56
|
+
service_params = signed_service_params(@aws_secret_access_key, service_hash, :post, @params[:server], @params[:service])
|
57
|
+
end
|
58
|
+
request = Net::HTTP::Post.new(service)
|
59
|
+
request.body = service_params
|
60
|
+
request['Content-Type'] = 'application/x-www-form-urlencoded'
|
61
|
+
else
|
62
|
+
request = Net::HTTP::Get.new("#{@params[:service]}?#{service_params}")
|
63
|
+
end
|
64
|
+
|
65
|
+
#puts "\n\n --------------- QUERY REQUEST TO AWS -------------- \n\n"
|
66
|
+
#puts "#{@params[:service]}?#{service_params}\n\n"
|
67
|
+
|
68
|
+
# prepare output hash
|
69
|
+
{ :request => request,
|
70
|
+
:server => @params[:server],
|
71
|
+
:port => @params[:port],
|
72
|
+
:protocol => @params[:protocol] }
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
# Sends request to Amazon and parses the response
|
77
|
+
# Raises AwsError if any banana happened
|
78
|
+
def request_info(request, parser)
|
79
|
+
thread = @params[:multi_thread] ? Thread.current : Thread.main
|
80
|
+
thread[:elb_connection] ||= Rightscale::HttpConnection.new(:exception => RightAws::AwsError, :logger => @logger)
|
81
|
+
request_info_impl(thread[:elb_connection], @@bench, request, parser)
|
82
|
+
end
|
83
|
+
|
84
|
+
#-----------------------------------------------------------------
|
85
|
+
# REQUESTS
|
86
|
+
#-----------------------------------------------------------------
|
87
|
+
|
88
|
+
def listMetrics()
|
89
|
+
|
90
|
+
params = { }
|
91
|
+
|
92
|
+
@logger.info("list Metrics ")
|
93
|
+
|
94
|
+
link = generate_request("ListMetrics", params)
|
95
|
+
resp = request_info(link, QMonListMetrics.new(:logger => @logger))
|
96
|
+
|
97
|
+
rescue Exception
|
98
|
+
on_exception
|
99
|
+
end
|
100
|
+
|
101
|
+
|
102
|
+
# measureName: CPUUtilization (Units: Percent), NetworkIn (Units: Bytes), NetworkOut (Units: Bytes), DiskWriteOps (Units: Count)
|
103
|
+
# DiskReadBytes (Units: Bytes), DiskReadOps (Units: Count), DiskWriteBytes (Units: Bytes)
|
104
|
+
# stats: array containing one or more of Minimum, Maximum, Sum, Average, Samples
|
105
|
+
# startTime : Timestamp to start
|
106
|
+
# endtime: Timestamp to end
|
107
|
+
# unit: Either Seconds, Percent, Bytes, Bits, Count, Bytes, Bits/Second, Count/Second, and None
|
108
|
+
# period: Integer 60 or multiple of 60
|
109
|
+
# dimension: Hash containing keys ImageId, AutoScalingGroupName, InstanceId, InstanceType
|
110
|
+
# customUnit: nil. not supported currently.
|
111
|
+
# namespace: AWS/EC2
|
112
|
+
|
113
|
+
def getMetricStatistics( measureName, stats, startTime, endTime, unit, period=60, dimensions=nil, customUnit=nil, namespace="AWS/EC2" )
|
114
|
+
|
115
|
+
params = {}
|
116
|
+
params['MeasureName'] = measureName
|
117
|
+
i=1
|
118
|
+
stats.each do |s|
|
119
|
+
params['Statistics.member.'+i.to_s] = s
|
120
|
+
i = i+1
|
121
|
+
end
|
122
|
+
params['Period'] = period
|
123
|
+
if (dimensions != nil)
|
124
|
+
i = 1
|
125
|
+
dimensions.each do |k, v|
|
126
|
+
params['Dimensions.member.'+i.to_s+".Name."+i.to_s] = k
|
127
|
+
params['Dimensions.member.'+i.to_s+".Value."+i.to_s] = v
|
128
|
+
i = i+1
|
129
|
+
end
|
130
|
+
end
|
131
|
+
params['StartTime'] = startTime
|
132
|
+
params['EndTime'] = endTime
|
133
|
+
params['Unit'] = unit
|
134
|
+
#params['CustomUnit'] = customUnit always nil
|
135
|
+
params['Namespace'] = namespace
|
136
|
+
|
137
|
+
@logger.info("get Metric Statistics ")
|
138
|
+
|
139
|
+
link = generate_request("GetMetricStatistics", params)
|
140
|
+
resp = request_info(link, QMonGetMetricStatistics.new(:logger => @logger))
|
141
|
+
|
142
|
+
rescue Exception
|
143
|
+
on_exception
|
144
|
+
end
|
145
|
+
|
146
|
+
|
147
|
+
|
148
|
+
#-----------------------------------------------------------------
|
149
|
+
# PARSERS: Instances
|
150
|
+
#-----------------------------------------------------------------
|
151
|
+
|
152
|
+
|
153
|
+
class QMonGetMetricStatistics < RightAws::RightAWSParser
|
154
|
+
|
155
|
+
def reset
|
156
|
+
@result = []
|
157
|
+
end
|
158
|
+
|
159
|
+
def tagstart(name, attributes)
|
160
|
+
@metric = {} if name == 'member'
|
161
|
+
end
|
162
|
+
|
163
|
+
def tagend(name)
|
164
|
+
case name
|
165
|
+
when 'Timestamp' then
|
166
|
+
@metric[:timestamp] = @text
|
167
|
+
when 'Samples' then
|
168
|
+
@metric[:samples] = @text
|
169
|
+
when 'Unit' then
|
170
|
+
@metric[:unit] = @text
|
171
|
+
when 'Average' then
|
172
|
+
@metric[:average] = @text
|
173
|
+
when 'Minimum' then
|
174
|
+
@metric[:minimum] = @text
|
175
|
+
when 'Maximum' then
|
176
|
+
@metric[:maximum] = @text
|
177
|
+
when 'Sum' then
|
178
|
+
@metric[:sum] = @text
|
179
|
+
when 'Value' then
|
180
|
+
@metric[:value] = @text
|
181
|
+
when 'member' then
|
182
|
+
@result << @metric
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
class QMonListMetrics < RightAws::RightAWSParser
|
188
|
+
|
189
|
+
def reset
|
190
|
+
@result = []
|
191
|
+
@namespace = ""
|
192
|
+
@measure_name = ""
|
193
|
+
end
|
194
|
+
|
195
|
+
def tagstart(name, attributes)
|
196
|
+
@metric = {} if name == 'member'
|
197
|
+
end
|
198
|
+
|
199
|
+
def tagend(name)
|
200
|
+
case name
|
201
|
+
when 'MeasureName' then
|
202
|
+
@measure_name = @text
|
203
|
+
when 'Namespace' then
|
204
|
+
@namespace = @text
|
205
|
+
when 'Name' then
|
206
|
+
@metric[:name] = @text
|
207
|
+
when 'Value' then
|
208
|
+
@metric[:value] = @text
|
209
|
+
when 'member' then
|
210
|
+
@metric[:namespace] = @namespace
|
211
|
+
@metric[:measure_name] = @measure_name
|
212
|
+
@result << @metric
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
|
218
|
+
end
|
219
|
+
|
220
|
+
|
221
|
+
end
|
222
|
+
|
data/lib/sdb/active_sdb.rb
CHANGED
@@ -115,6 +115,7 @@ module RightAws
|
|
115
115
|
# :pool (uses a connection pool with a maximum number of connections - NOT IMPLEMENTED YET)
|
116
116
|
# :logger => Logger Object # Logger instance: logs to STDOUT if omitted
|
117
117
|
# :nil_representation => 'mynil'} # interpret Ruby nil as this string value; i.e. use this string in SDB to represent Ruby nils (default is the string 'nil')
|
118
|
+
# :service_endpoint => '/' # Set this to /mdb/request.mgwsi for usage with M/DB
|
118
119
|
|
119
120
|
def establish_connection(aws_access_key_id=nil, aws_secret_access_key=nil, params={})
|
120
121
|
@connection = RightAws::SdbInterface.new(aws_access_key_id, aws_secret_access_key, params)
|
@@ -32,6 +32,7 @@ module RightAws
|
|
32
32
|
DEFAULT_HOST = 'sdb.amazonaws.com'
|
33
33
|
DEFAULT_PORT = 443
|
34
34
|
DEFAULT_PROTOCOL = 'https'
|
35
|
+
DEFAULT_ENDPOINT = '/'
|
35
36
|
API_VERSION = '2009-04-15'
|
36
37
|
DEFAULT_NIL_REPRESENTATION = 'nil'
|
37
38
|
|
@@ -56,6 +57,7 @@ module RightAws
|
|
56
57
|
# :pool (uses a connection pool with a maximum number of connections - NOT IMPLEMENTED YET)
|
57
58
|
# :logger => Logger Object # Logger instance: logs to STDOUT if omitted
|
58
59
|
# :nil_representation => 'mynil'} # interpret Ruby nil as this string value; i.e. use this string in SDB to represent Ruby nils (default is the string 'nil')
|
60
|
+
# :service_endpoint => '/' # Set this to /mdb/request.mgwsi for usage with M/DB #
|
59
61
|
#
|
60
62
|
# Example:
|
61
63
|
#
|
@@ -69,7 +71,8 @@ module RightAws
|
|
69
71
|
init({ :name => 'SDB',
|
70
72
|
:default_host => ENV['SDB_URL'] ? URI.parse(ENV['SDB_URL']).host : DEFAULT_HOST,
|
71
73
|
:default_port => ENV['SDB_URL'] ? URI.parse(ENV['SDB_URL']).port : DEFAULT_PORT,
|
72
|
-
:default_protocol => ENV['SDB_URL'] ? URI.parse(ENV['SDB_URL']).scheme : DEFAULT_PROTOCOL
|
74
|
+
:default_protocol => ENV['SDB_URL'] ? URI.parse(ENV['SDB_URL']).scheme : DEFAULT_PROTOCOL,
|
75
|
+
:service_endpoint => ENV['SDB_URL'] ? URI.parse(ENV['SDB_URL']).path : DEFAULT_ENDPOINT },
|
73
76
|
aws_access_key_id || ENV['AWS_ACCESS_KEY_ID'],
|
74
77
|
aws_secret_access_key || ENV['AWS_SECRET_ACCESS_KEY'],
|
75
78
|
params)
|
@@ -83,7 +86,7 @@ module RightAws
|
|
83
86
|
params.delete_if {|key,value| value.nil? }
|
84
87
|
#params_string = params.to_a.collect{|key,val| key + "=#{CGI::escape(val.to_s)}" }.join("&")
|
85
88
|
# prepare service data
|
86
|
-
service =
|
89
|
+
service = @params[:service_endpoint]
|
87
90
|
service_hash = {"Action" => action,
|
88
91
|
"AWSAccessKeyId" => @aws_access_key_id,
|
89
92
|
"Version" => API_VERSION }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: appoxy-aws
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.11.
|
4
|
+
version: 1.11.35
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Travis Reeder
|
@@ -11,7 +11,7 @@ autorequire:
|
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
13
|
|
14
|
-
date: 2009-09-
|
14
|
+
date: 2009-09-25 00:00:00 -07:00
|
15
15
|
default_executable:
|
16
16
|
dependencies: []
|
17
17
|
|
@@ -29,6 +29,7 @@ files:
|
|
29
29
|
- lib/awsbase/right_awsbase.rb
|
30
30
|
- lib/awsbase/support.rb
|
31
31
|
- lib/ec2/right_ec2.rb
|
32
|
+
- lib/ec2/right_mon_interface.rb
|
32
33
|
- lib/elb/right_elb_interface.rb
|
33
34
|
- lib/right_aws.rb
|
34
35
|
- lib/s3/right_s3.rb
|