Kalyan
Kalyan

Reputation: 23

AWS Cloudwatch get-metric-statistics command is returning the metric name instead of the value for custom cloudwatch metrics

I enabled detailed level memory monitoring on cloudwatch for one of my instances using the cloudwatch agent. The metrics are visible on the cloudwatch console but when I try to query the metric using the AWS CLI, I am not getting any value and the command is returning the name of the metric.

The command I am using is aws cloudwatch get-metric-statistics --namespace CWAgent --metric-name mem_used --period 86400 --dimensions Name=InstanceId,Value=i-0059a97647b41a16d Name=ImageId,Value=ami-0c322300a1dd5dc79 Name=InstanceType,Value=t2.micro Name="Instance Name",Value=cloudwatch --start-time 2019-09-27T00:00:00Z --end-time 2019-09-27T23:59:59Z --statistic Minimum --unit Megabits --region us-east-1

After running this command, the response is - mem_used

Upvotes: 0

Views: 1829

Answers (1)

Dejan Peretin
Dejan Peretin

Reputation: 12119

CloudWatch Agent emits mem_used in Bytes unit (docs) and there is not automatic unit conversion.

Try changing the unit to Bytes or removing the unit altogether from the command.

There could be other things wrong here, but let's start with the unit.

--

Second thing (from conversation in the comments) was an extra dimension used in the command. Final command would be then:

aws cloudwatch get-metric-statistics \
--namespace CWAgent \
--metric-name mem_used \
--period 86400 \
--dimensions Name=InstanceId,Value=i-0059a97647b41a16d Name=ImageId,Value=ami-0c322300a1dd5dc79 Name=InstanceType,Value=t2.micro \
--start-time 2019-09-27T00:00:00Z \
--end-time 2019-09-27T23:59:59Z \
--statistic Minimum \
--region us-east-1

Upvotes: 0

Related Questions