1

我正在尝试探索 simple_aws gem。当我连接到 cloudwatch 以获取指标统计信息时,我收到如下错误:

cw.get_metric_statistics(
 :metric_name => metric_name,
 :period => period,
 :start_time => start_time,
 :end_time => end_time,
 :statistics => "Average",
 :namespace => "AWS/EC2"
)

SimpleAWS::UnsuccessfulResponse: MissingParameter (400):

   The parameter Namespace is required.
   The parameter MetricName is required.  
   The parameter StartTime is required.  
   The parameter EndTime is required.  
   The parameter Period is required.  
   The parameter Statistics is required. 

后来,我尝试了这个:

cw.get_metric_statistics(
options => [
  {:metric_name=>"CPUUtilization",
   :period=>60,
   :start_time => Time.now()-86400,
   :end_time => Time.now()-3600,
   :statistics => "Average"
  }
]
)

但出现以下错误:

URI::InvalidComponentError: bad component(expected query component): 

Action=GetMetricStatistics&{:metric_name=>"CPUUtilization"}.1.metric_name=CPUUtilization&{:metric_name=>"CPUUtilization"}.1.period=60&{:metric_name=>"CPUUtilization"}.1.start_time=2012-05-06%2014%3A25%3A28%20%2B0530&{:metric_name=>"CPUUtilization"}.1.end_time=2012-05-07%2013%3A25%3A28%20%2B0530&{:metric_name=>"CPUUtilization"}.1.statistics=Average&AWSAccessKeyId=AccessKey&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2012-05-07T08%3A55%3A28Z&Version=2010-08-01&Signature=Signature

再试一次:

cw.get_metric_statistics(
namespace: 'AWS/EC2',
measure_name: 'CPUUtilization',
statistics: 'Average',
start_time: time-1000,
dimensions: "InstanceId=#{instance_id}"

)

ArgumentError:Array 与 Array 的比较失败

任何人都可以帮助找到发出此命令的正确语法。

4

2 回答 2

2
result = cw.get_metric_statistics(step,
      start_time,
      end_time,
      metric,
      'AWS/RDS',
      'Average',
      dimensions={'DBInstanceIdentifier': [indentifier]})

这也对我有用

于 2015-02-15T07:10:16.273 回答
1

我发现这行得通;

lat = cw.get_metric_statistics(
  'MetricName' => 'Latency',
  'Period' => 60,
  'StartTime' => (Time.now() - 3600).iso8601,
  'EndTime' => Time.now().iso8601,
  'Statistics.member.1' => "Average",
  'Namespace' => "AWS/ELB",
  'Unit' => 'Seconds'
)

首先需要ISO8601格式的日期时间,其次需要正确大小写参数,第三需要Unit参数,最后Statistics需要一个命名空间(?)。

希望这会有所帮助,即使它有点晚了。

于 2012-05-29T23:53:48.060 回答