mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
split out and got passing get metric statistics request tests
This commit is contained in:
parent
d0383c177a
commit
22f9ccc75c
4 changed files with 99 additions and 6 deletions
|
@ -3,7 +3,7 @@ module Fog
|
|||
module AWS
|
||||
module CloudWatch
|
||||
|
||||
class GetMetricStatisticsResult < Fog::Parsers::Base
|
||||
class GetMetricStatistics < Fog::Parsers::Base
|
||||
|
||||
def reset
|
||||
@response = { 'GetMetricStatisticsResult' => {'Datapoints' => []}, 'ResponseMetadata' => {} }
|
||||
|
@ -21,16 +21,18 @@ module Fog
|
|||
def end_element(name)
|
||||
case name
|
||||
when 'Average', 'Maximum', 'Minimum', 'SampleCount', 'Sum'
|
||||
@datapoint[name] = @value.to_f
|
||||
@datapoint[name] = value.to_f
|
||||
when 'Unit'
|
||||
@datapoint[name] = @value
|
||||
@datapoint[name] = value
|
||||
when 'Timestamp'
|
||||
@datapoint[name] = Time.parse @value
|
||||
when 'Datapoint'
|
||||
@datapoint[name] = Time.parse value
|
||||
when 'member'
|
||||
@response['GetMetricStatisticsResult']['Datapoints'] << @datapoint
|
||||
reset_datapoint
|
||||
when 'Label'
|
||||
@response['GetMetricStatisticsResult'][name] = value
|
||||
when 'RequestId'
|
||||
@response['ResponseMetadata'][name] = @value
|
||||
@response['ResponseMetadata'][name] = value
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -25,6 +25,9 @@ module Fog
|
|||
# http://docs.amazonwebservices.com/AmazonCloudWatch/latest/APIReference/API_GetMetricStatistics.html
|
||||
#
|
||||
def get_metric_statistics(options={})
|
||||
%w{Statistics StartTime EndTime Period MetricName Namespace}.each do |required_parameter|
|
||||
raise ArgumentError, "Must prodide #{required_parameter}" unless options.has_key?(required_parameter)
|
||||
end
|
||||
statistics = options.delete 'Statistics'
|
||||
options.merge!(AWS.indexed_param('Statistics.member.%d', [*statistics]))
|
||||
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
Shindo.tests('AWS::CloudWatch | metric requests', ['aws', 'cloudwatch']) do
|
||||
tests('success') do
|
||||
|
||||
@metrics_statistic_format = {
|
||||
'GetMetricStatisticsResult' => {
|
||||
'Label' => String,
|
||||
'Datapoints' => [{
|
||||
"Timestamp" => Time,
|
||||
'Unit' => String,
|
||||
'Minimum' => Float,
|
||||
'Maximum' => Float,
|
||||
'Average' => Float,
|
||||
'Sum' => Float,
|
||||
'SampleCount' => Float
|
||||
}],
|
||||
},
|
||||
'ResponseMetadata' => {
|
||||
'RequestId' => String
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
tests("#get_metric_statistics").formats(@metrics_statistic_format) do
|
||||
instanceId = 'i-420c352f'
|
||||
AWS[:cloud_watch].get_metric_statistics({'Statistics' => ['Minimum','Maximum','Sum','SampleCount','Average'], 'StartTime' => (Time.now-600).iso8601, 'EndTime' => Time.now.iso8601, 'Period' => 60, 'MetricName' => 'DiskReadBytes', 'Namespace' => 'AWS/EC2', 'Dimensions' => [{'Name' => 'InstanceId', 'Value' => instanceId}], 'Region' => 'eu-west-1'}).body
|
||||
end
|
||||
end
|
||||
end
|
60
tests/aws/requests/cloud_watch/list_metrics_test.rb
Normal file
60
tests/aws/requests/cloud_watch/list_metrics_test.rb
Normal file
|
@ -0,0 +1,60 @@
|
|||
Shindo.tests('AWS::CloudWatch | metric requests', ['aws', 'cloudwatch']) do
|
||||
|
||||
tests('success') do
|
||||
@metrics_list_format = {
|
||||
'ListMetricsResult' => {
|
||||
'Metrics' =>
|
||||
[{
|
||||
'Dimensions' =>
|
||||
[{
|
||||
'Name' => String,
|
||||
'Value' => String
|
||||
}],
|
||||
"MetricName" => String,
|
||||
"Namespace" => String
|
||||
}],
|
||||
'NextToken' => Fog::Nullable::String,
|
||||
},
|
||||
'ResponseMetadata' => {"RequestId"=> String},
|
||||
}
|
||||
@instanceId = 'i-2f3eab59'
|
||||
@dimension_filtered_metrics_list_format = {
|
||||
'ListMetricsResult' => {
|
||||
'Metrics' =>
|
||||
[{
|
||||
'Dimensions' =>
|
||||
[{
|
||||
'Name' => 'InstanceId',
|
||||
'Value' => @instanceId
|
||||
}],
|
||||
"MetricName" => String,
|
||||
"Namespace" => String
|
||||
}],
|
||||
'NextToken' => Fog::Nullable::String,
|
||||
},
|
||||
'ResponseMetadata' => {"RequestId"=> String},
|
||||
}
|
||||
|
||||
tests("#list_metrics").formats(@metrics_list_format) do
|
||||
AWS[:cloud_watch].list_metrics.body
|
||||
end
|
||||
|
||||
tests("#dimension_filtered_list_metrics").formats(@dimension_filtered_metrics_list_format) do
|
||||
AWS[:cloud_watch].list_metrics('Dimensions' => [{'Name' => 'InstanceId', 'Value' => @instanceId}]).body
|
||||
end
|
||||
|
||||
tests("#metric_name_filtered_list_metrics").returns(true) do
|
||||
metricName = "CPUUtilization"
|
||||
AWS[:cloud_watch].list_metrics('MetricName' => metricName).body['ListMetricsResult']['Metrics'].all? do |metric|
|
||||
metric['MetricName'] == metricName
|
||||
end
|
||||
end
|
||||
|
||||
tests("#namespace_filtered_list_metrics").returns(true) do
|
||||
namespace = "AWS/EC2"
|
||||
AWS[:cloud_watch].list_metrics('Namespace' => namespace).body['ListMetricsResult']['Metrics'].all? do |metric|
|
||||
metric['Namespace'] == namespace
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Reference in a new issue