我正在尝试使用 Rails 中的 Ruby SDK v2 从 cloudwatch 获取 CPU 指标。
metric = Aws::CloudWatch::Metric.new( 'AWS/EC2', 'CPUUtilization', region: 'eu-west-1')
@stats = metric.get_statistics({
dimensions: [{ :name => 'InstanceID', :value => 'i-14b21212' }],
start_time: 2.days.ago.utc.iso8601,
end_time: Time.now.utc.iso8601,
period: 300,
statistics: ["Average"]
})
这不会出错,但不会返回任何数据点。我已经用一个启用了高级监控的实例和一个没有任何东西的实例来尝试这个。
以上返回:
[Aws::CloudWatch::Client 200 0.639127 0 retries] get_metric_statistics(dimensions:[{name:"InstanceID",value:"[FILTERED]"}],start_time:2016-12-13 17:17:53 UTC,end_time:2016-12-15 17:17:53 UTC,period:300,statistics:["Average"],namespace:"AWS/EC2",metric_name:"CPUUtilization")
=> #<struct Aws::CloudWatch::Types::GetMetricStatisticsOutput label="CPUUtilization", datapoints=[]>
我也试过这个,但仍然一无所获:
metric = Aws::CloudWatch::Metric.new( 'AWS/EC2', 'CPUUtilization', region: 'eu-west-1')
@stats = metric.get_statistics({
dimensions: [{ :name => 'InstanceID', :value => 'i-14b21212' }],
start_time: 2.days.ago.utc.iso8601,
end_time: Time.now.utc.iso8601,
period: 300,
extended_statistics: ["p10", "p20", "p30", "p40", "p50", "p60", "p70", "p80", "p90", "p100"]
})
对我做错的任何帮助都会很棒!