I want to use CloudWatch to get CPU usage from the instanced created in the same program. mon-get-stats could get the metric from the instance id I specified. But when I use Ruby AWS API as below, it returns nothing. I have tried some methods in other website, but none works.
Any suggestion about this issue? Thanks in advance!
metric = AWS::CloudWatch::Metric.new( 'AWS/EC2', 'CPUUtilization',
:dimensions => [{ :name => 'InstanceID', :value => 'i-63be8f06' }])
stats = metric.statistics(
:start_time => '2013-09-21T17:01:00',
:end_time => '2013-09-21T17:11:00',
:period => 60,
:statistics => ['Average'])
stats.each do |datapoint|
puts datapoint
end
You are querying :period => 60 .. is it definitely a 1minute metric ? .. do you have detailed monitoring enabled for that instance ? ..
Try your query with :period => 300 and see if you get any data back (i.e query for 5 min)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With