aws-sdk-cloudwatch 0.0.6 → 1.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,29 +0,0 @@
1
- require 'aws/core/inflection'
2
- require 'aws/core/option_grammar'
3
- require 'aws/core/meta_utils'
4
-
5
- module AWS
6
- module Core
7
- class OptionGrammar
8
- module Descriptors
9
-
10
- # @private
11
- module Double
12
-
13
- extend NoArgs
14
-
15
- def validate(value, context = nil)
16
- raise format_error("float value", context) unless
17
- value.respond_to? :to_f
18
- end
19
-
20
- def encode_value(value)
21
- value.to_s
22
- end
23
-
24
- end
25
-
26
- end
27
- end
28
- end
29
- end
data/licence.rb DELETED
@@ -1,14 +0,0 @@
1
- # Copyright 2012 Inscitiv
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
@@ -1,27 +0,0 @@
1
- # Copyright 2012 Inscitiv
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
- require 'aws/cloud_watch/client'
16
-
17
- describe AWS::CloudWatch::Client, '.api_config' do
18
- it 'loads api config from proper directory' do
19
- expected_dir = Pathname.new(File.dirname(__FILE__)).parent
20
- expected_file = expected_dir.to_s + '/lib/aws/api_config/CloudWatch-2010-08-01.yml'
21
-
22
- File.should_receive(:read).with(expected_file).and_return(file = double)
23
- YAML.should_receive(:load).with(file).and_return(api = double)
24
-
25
- AWS::CloudWatch::Client.api_config.should == api
26
- end
27
- end
@@ -1,70 +0,0 @@
1
- # Copyright 2012 Inscitiv
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
- require 'aws/cloud_watch/ec2'
16
-
17
- describe AWS::EC2::Instance, '#metrics' do
18
- it 'returns the collection of metrics filtered by the instance' do
19
- inst = AWS::EC2::Instance.new :test_id
20
- ms = inst.metrics
21
- ms.kind_of? AWS::CloudWatch::MetricCollection.should be_true
22
- ms.namespace.should == 'AWS/EC2'
23
- ms.dimensions[:instance_id].should == :test_id
24
- end
25
-
26
- it 'always returns the same instance of the collection' do
27
- inst = AWS::EC2::Instance.new :test_id
28
- ms = inst.metrics
29
- inst.metrics.should === ms
30
- end
31
- end
32
-
33
- describe AWS::EC2::Instance, '#cpu_utilization' do
34
- before :each do
35
- @inst = AWS::EC2::Instance.new :some_id
36
- end
37
-
38
- it 'uses the proper metrics' do
39
- @inst.cpu_utilization.name.should == 'CPUUtilization'
40
- end
41
-
42
- it 'aggregates by average by default' do
43
- @inst.should_receive(:metrics).and_return(double :[] => (metric = double))
44
- metric.should_receive(:average).with(:some, :args).and_return(result = double)
45
-
46
- @inst.cpu_utilization(:some, :args).should == result
47
- end
48
- end
49
-
50
- describe AWS::EC2::Instance, ' synthetic metric methods' do
51
- before :each do
52
- @inst = AWS::EC2::Instance.new :some_id
53
- @ms = @inst.metrics
54
- end
55
-
56
- it 'retrieves the proper metric and aggregates by sum' do
57
- [:disk_read_ops, :disk_write_ops, :network_out, :disk_read_bytes, :network_in, :disk_write_bytes].each do |name|
58
- @inst.send(name).name == name
59
- end
60
- end
61
-
62
- it 'aggregates the metric with sum' do
63
- [:disk_read_ops, :disk_write_ops, :network_out, :disk_read_bytes, :network_in, :disk_write_bytes].each do |name|
64
- @ms.should_receive(:[]).with(name).and_return(metric = double)
65
- metric.should_receive(:sum).with(:some, :args).and_return(result = double)
66
-
67
- @inst.send(name, :some, :args).should == result
68
- end
69
- end
70
- end
@@ -1,50 +0,0 @@
1
- # Copyright 2012 Inscitiv
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
- require 'aws/cloud_watch/metric_base'
16
-
17
- describe AWS::CloudWatch::MetricBase do
18
- it 'puts unknown keys in dimensions when initializing' do
19
- mb = AWS::CloudWatch::MetricBase.new :name => :foo,
20
- 'Something' => :bar, :other => :baz
21
- mb.name.should == :foo
22
- mb.dimensions[:other].should == :baz
23
- mb.dimensions['Something'].should == :bar
24
- end
25
- end
26
-
27
- describe AWS::CloudWatch::MetricBase, '#dimensions=' do
28
- it 'transforms argument into direct hash form' do
29
- mb = AWS::CloudWatch::MetricBase.new({})
30
- mb.dimensions = [{:name => 'Test', :value => 'dimension'},
31
- {:name => :another, :value => :dimension}]
32
- mb.dimensions.should == {'Test' => 'dimension',
33
- :another => :dimension}
34
- end
35
- end
36
-
37
- describe AWS::CloudWatch::MetricBase, '#options' do
38
- it 'folds all parameters into a single hash ready for sending to AWS' do
39
- mb = AWS::CloudWatch::MetricBase.new :name => :foo,
40
- 'Something' => :bar, :other => :baz
41
- options = mb.options
42
- options.keys.length.should == 2
43
- options[:metric_name].should == :foo
44
- dims = options[:dimensions]
45
- dims.length.should == 2
46
- [ { :name => 'Something', :value => :bar }, { :name => 'Other', :value => :baz } ].each do |dim|
47
- dims.include?(dim).should be_true
48
- end
49
- end
50
- end
@@ -1,46 +0,0 @@
1
- # Copyright 2012 Inscitiv
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
- require 'aws/cloud_watch/metric_collection'
16
-
17
- describe AWS::CloudWatch::MetricCollection, '#each' do
18
- it 'paginates through a token' do
19
- mc = AWS::CloudWatch::MetricCollection.new({})
20
- client = double("client")
21
- mc.should_receive(:client).any_number_of_times.and_return(client)
22
-
23
- names = [:one, :two, :three, :four]
24
- first_page = names[0..1].map {|n| {:name => n}}
25
- second_page = names[2..3].map {|n| {:name => n}}
26
-
27
- client.should_receive(:list_metrics).and_return(stub :metrics => first_page, :data => {:next_token => :a_token})
28
- client.should_receive(:list_metrics) do |options|
29
- options[:next_token].should == :a_token
30
- stub :metrics => second_page, :data => {}
31
- end
32
-
33
- mc.each do |metric|
34
- metric.name.should == names.shift
35
- end
36
- end
37
- end
38
-
39
- describe AWS::CloudWatch::MetricCollection, '#[]' do
40
- it 'makes a metric with the given name' do
41
- mc = AWS::CloudWatch::MetricCollection.new :namespace => :foo
42
- metric = mc[:some_name]
43
- metric.name.should == 'SomeName'
44
- metric.namespace.should == :foo
45
- end
46
- end
@@ -1,159 +0,0 @@
1
- # Copyright 2012 Inscitiv
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
- require 'aws/cloud_watch/metric'
16
-
17
- describe AWS::CloudWatch::Metric, '#options' do
18
- it 'also takes the unit' do
19
- m = AWS::CloudWatch::Metric.new :unit => 'barn'
20
- m.options[:unit].should == 'barn'
21
- end
22
- end
23
-
24
- describe AWS::CloudWatch::Metric, '#get' do
25
- before(:each) do
26
- @metric = AWS::CloudWatch::Metric.new({})
27
- @metric.should_receive(:client).any_number_of_times.and_return(@client = double)
28
- @begin = Time.utc(2000, 1, 2, 2, 2, 2)
29
- @begin_iso = "2000-01-02T02:02:02Z"
30
- @end = Time.utc(2000, 2, 2, 2, 2, 3)
31
- @end_iso = "2000-02-02T02:02:03Z"
32
- end
33
-
34
- it 'can collect a single statistic' do
35
- @client.should_receive(:get_metric_statistics).with(\
36
- :start_time => @begin_iso,
37
- :end_time => @end_iso,
38
- :period => 4600,
39
- :statistics => ["Sum"]
40
- ).and_return(double :datapoints => [])
41
- @metric.get(:sum, 4600, @begin..@end)
42
- end
43
-
44
- it 'collects one period worth of data if no range is given' do
45
- @client.should_receive(:get_metric_statistics).with(\
46
- :start_time => "2000-02-02T01:02:03Z",
47
- :end_time => @end_iso,
48
- :period => 60*60, # one hour
49
- :statistics => ["Sum"]
50
- ).and_return(double :datapoints => [{:sum => :result}])
51
- @metric.get(:sum, 60 * 60, @end).should == :result
52
- end
53
-
54
- it 'returns nil when no datapoinst are returned' do
55
- @client.should_receive(:get_metric_statistics).with(\
56
- :start_time => "2000-02-02T01:02:03Z",
57
- :end_time => @end_iso,
58
- :period => 60*60, # one hour
59
- :statistics => ["Sum"]
60
- ).and_return(double :datapoints => [])
61
- @metric.get(:sum, 60 * 60, @end).should be_nil
62
- end
63
-
64
- it 'returns stats sorted by timestamp' do
65
- datapoints = [
66
- {:timestamp => Time.utc(2001, 4, 2, 5, 2, 0)},
67
- {:timestamp => Time.utc(2011, 3, 1, 12, 4, 32)},
68
- {:timestamp => Time.utc(2000, 1, 5, 2, 3, 0)}
69
- ]
70
- sorted = [
71
- {:timestamp => Time.utc(2000, 1, 5, 2, 3, 0)},
72
- {:timestamp => Time.utc(2001, 4, 2, 5, 2, 0)},
73
- {:timestamp => Time.utc(2011, 3, 1, 12, 4, 32)}
74
- ]
75
-
76
- @client.should_receive(:get_metric_statistics).with(\
77
- :start_time => @begin_iso,
78
- :end_time => @end_iso,
79
- :period => 4600,
80
- :statistics => ["Sum"]
81
- ).and_return(double :datapoints => datapoints)
82
- @metric.get(:sum, 4600, @begin..@end).should == sorted
83
- end
84
-
85
- it 'fetches many batches if number of datapoints is too large' do
86
- _begin = Time.utc(2012, 01, 01, 0, 0, 0)
87
- _end = Time.utc(2012, 01, 03, 0, 0, 0)
88
-
89
- @client.should_receive(:get_metric_statistics).with(\
90
- :start_time => "2012-01-01T00:00:00Z",
91
- :end_time => "2012-01-02T00:00:00Z",
92
- :period => 60,
93
- :statistics => ["Sum"]
94
- ).and_return(double :datapoints => [1, 2, 3])
95
- @client.should_receive(:get_metric_statistics).with(\
96
- :start_time => "2012-01-02T00:00:00Z",
97
- :end_time => "2012-01-03T00:00:00Z",
98
- :period => 60,
99
- :statistics => ["Sum"]
100
- ).and_return(double :datapoints => [4, 5, 6])
101
- @metric.get(:sum, 60, _begin.._end).should == [1, 2, 3, 4, 5, 6]
102
- end
103
-
104
- it 'handles minute differences in begin and end times gracefully' do
105
- _begin = Time.utc(2012, 6, 8, 17, 36, 58, 901063)
106
- _end = Time.utc(2012, 6, 13, 17, 36, 58, 901588)
107
-
108
- @client.should_receive(:get_metric_statistics).with(\
109
- :start_time => "2012-06-08T17:36:58Z",
110
- :end_time => "2012-06-13T17:36:58Z",
111
- :period => 300,
112
- :statistics => ["Sum"]
113
- ).and_return(double :datapoints => [1, 2, 3])
114
- @client.should_not_receive(:get_metric_statistics).with(\
115
- :start_time => "2012-06-13T17:36:58Z",
116
- :end_time => "2012-06-13T17:36:58Z",
117
- :period => 300,
118
- :statistics => ["Sum"]
119
- )
120
- @metric.get(:sum, 300, _begin.._end).should == [1, 2, 3]
121
- end
122
-
123
- it 'returns [] trivially if range is shorter than period' do
124
- _begin = Time.utc(2012, 6, 8, 17, 36, 58)
125
- _end = Time.utc(2012, 6, 8, 17, 41, 57)
126
- @client.should_not_receive:get_metric_statistics
127
- @metric.get(:sum, 300, _begin.._end).should == []
128
- end
129
- end
130
-
131
- describe AWS::CloudWatch::Metric, " synthetic methods" do
132
- before(:each) do
133
- @metric = AWS::CloudWatch::Metric.new({})
134
- @metric.stub(:client => (@client = double))
135
- @begin = Time.utc(2000, 2, 2, 2, 2, 2)
136
- @begin_iso = "2000-02-02T02:02:02Z"
137
- @end = Time.utc(2000, 2, 2, 4, 2, 3)
138
- @end_iso = "2000-02-02T04:02:03Z"
139
- end
140
-
141
- it "fetches proper statistic and substitutes :value field" do
142
- stats = {:average => 'Average',
143
- :sum => 'Sum',
144
- :sample_count => 'SampleCount',
145
- :maximum => 'Maximum',
146
- :minimum => 'Minimum'
147
- }
148
-
149
- stats.keys.each do |name|
150
- @client.should_receive(:get_metric_statistics).with(\
151
- :start_time => @begin_iso,
152
- :end_time => @end_iso,
153
- :period => 60*60, # one hour
154
- :statistics => [stats[name]]
155
- ).and_return(double :datapoints => [{name => :result}])
156
- @metric.send(name, 60 * 60, (@begin..@end))[0][:value].should == :result
157
- end
158
- end
159
- end