karthik v
karthik v

Reputation: 1172

Why am I unable to fetch metric values for EC2 instances from cloudwatch?

I am trying to get the cloudwatch metric data for CPU Utilazation of an EC2 instance i-014448f54423cc0, but i am getting the following output without any metrics data

AWS CLI COMMAND

$ aws cloudwatch get-metric-statistics --metric-name CPUUtilization --start-time 2017-03-20T23:18:00 --end-time 2017-03-25T23:18:00 --period 3600 --namespace AWS/EC2 --statistics Average --dimensions Name=i-014448f54423cc0,Value=i-abcdef

OUTPUT

-----------------------------
|    GetMetricStatistics    |
+--------+------------------+
|  Label |  CPUUtilization  |
+--------+------------------+

As per the following thread on AWS forum: Link It is said that cloudwatch metrics data can be accessed through API's only if detailed monitoring is enabled, so I tried both scenarios of with & without enabling detailed monitoring but still in both the cases the output is same

Upvotes: 2

Views: 1379

Answers (1)

Anthony Neace
Anthony Neace

Reputation: 26003

You have defined your dimension incorrectly. The dimension you are filtering (literally 'InstanceId') needs to be defined as the Name, and your value (in this case, the instance id's value) as the Value.

Example

Snippet:

Name=InstanceId,Value=i-014448f54423cc0

Full example:

aws cloudwatch get-metric-statistics --metric-name CPUUtilization --start-time 2017-03-20T23:18:00 --end-time 2017-03-25T23:18:00 --period 3600 --namespace AWS/EC2 --statistics Average --dimensions Name=InstanceId,Value=i-014448f54423cc0

Discussion

The linked AWS forum discussion isn't relevant to this situation, because detailed monitoring only enables monitoring at 1-minute granularity. Basic monitoring samples data on five-minute intervals. Since you are requesting CPUUtilization for each hour (period=3600 seconds) on a single instance, you will have data available with no need for detailed monitoring.

Further Reading

Upvotes: 4

Related Questions